
The second strategy is the comparing consecutive snapshots to explore new allocations, i.e. So sorting by Hit Count helps to identify what places in the code constantly allocate resources: Just for example, let's add a timer that allocates some memory every 50 ms: MainWindow::MainWindow(QWidget *parent) :Ĭonnect(timer, SIGNAL(timeout()), this, SLOT(onTimer())) įirst of all, it's very easy to look at memory usage in the Deleaker:Īll allocations are grouped by call stacks, Hit Count shows number of allocations that have the same call stack, i.e.

In case it's incorrect Deleaker offers two strategies to fix such resource leakage. It may be correct or incorrect, depending on the logic. Sometimes a process allocates more and more memory, but don't free it. If a source file and a line are available, Deleaker opens the source file directly in the code editor by double-clicking (or through the context menu): We call such allocations as leaks.įor each memory block one can review its call stack to understand where in the code this memory was allocated. When a process exits, Deleaker automatically takes a final snapshot that contains all allocations that haven't been freed. You can explore all currently allocated resources, including memory, by clicking on Take Snapshot: QPushButton* button1 = new QPushButton("button1") QPushButton* button = new QPushButton("button") Imagine that someone allocated QPushButton but then decided not to add it to a layout: MainWindow::MainWindow(QWidget *parent) : Then introduce a leak, allocating one instance of QPushButton.

Let's create a new project (Qt Widgets Application) to look how Deleaker detects leaks. To open Deleaker Windows just click on it: If Deleaker works as a plugin, a developer can find leaks without leaving Qt Creator in order to move to the source of possible errors quicker.Īfter installation, a new Deleaker item is added to the Qt Creator main menu. Deleaker Standalone is convenient, for example, if Qt Creator is not available.
#Qt creator tutorial how to
In this tutorial you will find how to check C++ memory leaks in Qt with the help of Deleaker.ĭeleaker can work either as a standalone application, or as a Qt Creator plugin.
