How can I detect memory leaks in QtCreator on Windows? On the doc, they recommend Memcheck but it only works on Mac and Linux. Any suggestion for Windows?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
New 2017 solution
quote by
@this.lau_
1) Open the Qt SDK command line tool and run:
qmake -spec win32-msvc2015 -tp vc
2) Install Visual Leak Detector for Visual C++
3) Open a .vcxproj that was created with the step
1
4) Include into your
main.cpp
#include <vld.h>
5) Launch DebugView v4.81
6) Than run your project
ctrl + F5
Here's an even more recent answer. Qt Creator 4.7.1 now supports heob, which is a leak detector too. You can down it for Windows from here: "heob download | SourceForge.net". Extract it somewhere, get a recent version of Qt Creator, and go to Analyze | heob. Direct it to yer .exe, choose yer options, click the little disk icon to save yer opts, and click OK to run yer proggie. It gives u a nice little memcheck window that seems to give you stack dumps at the time the objects were allocated, which u can unfold and see the offending objects; when you use the Detect Leak Types option. You can even navigate to the source line where the new occurred by clicking the link.
After many tries I finally found a method to detect the memory leaks of a Qt project on Windows:
1) First, it cannot be done directly in Qt Creator so you need to create a Visual C++ project to do the memory leak detection. Thankfully, qmake makes this easy. Open the Qt SDK command line tool and run:
This will convert your project to a .vcproj.
2) Open this project and add the necessary code for memory leak detection:
To your main.cpp file:
3) With this, your project should now be able to detect memory leaks. Note the
_MSC_VER
defines so that this code is only executed when your run it from Visual C++ (not from Qt Creator). It means you can still do the development with Qt Creator and just re-run step 1 whenever you need to check for memory leaks.4) To break at a particular memory allocation, use
_CrtSetBreakAlloc()
More information memory leak detection on Microsoft's website: http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx