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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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_VERdefines 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