[Qt-interest] How to detect memory leaks
Santhosh Y
santhosh at softjin.com
Mon Jul 12 11:51:38 CEST 2010
> I think you can use _CrtMemCheckpoint, _CrtMemDifference to detect
> memory leak on Windows.
Please see my below main(); Here I declared a variable s1,s2,s3, and I
used with *CrtMemCheckpoint & * *CrtDumpMemoryLeaks** *as shown below
=================================================
*_CrtMemState s1; // Global declaration*
*_CrtMemState s2; // Global declaration*
*_CrtMemState s3; // Global declaration*
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(gui);
* _CrtMemCheckpoint(&s1);*
NewGUICOMObj appobject(argv[0]);
if (appobject.createInstance() == -1) {
// failure in create instance call
return -1;
}
//successfully launched event loop
int value = app.exec();
* _CrtMemCheckpoint(&s2);*
if(_*CrtMemDifference(&s3, &s1, &s2)*)
{
printf("\nOOps! Memory leak detected\n") ;
* _CrtDumpMemoryLeaks() ; *
// alternatively you can use _CrtMemDumpAllObjectsSince for
//dumping from specific check point
}
return value;
}
=================================================
/// output is :-
Dumping objects ->
{166167} normal block at 0x0ED00018, 16 bytes long.
Data: < Z 0 Z 0 Z e> B8 B1 5A 02 30 85 5A 03 30 85 5A 03 C4 CC B2 65
{163467} normal block at 0x0ECFB9B8, 80 bytes long.
Data: < ~ > D0 7E CF 0E 00 0C 00 A0 01 08 00 A0 00 02 00 00
{162176} normal block at 0x0ECFB508, 124 bytes long.
Object dump complete.
*How to read the above output. How to make out where the 16 bytes memory
leak is present in my source code!*
Please tell me is this the correct way of doing this.
Thanks
>
> For Linux, since there is no similar API to do the heap check, you can
> use Valgrind (|VALGRIND_COUNT_LEAKS)
>
> Regards
>
> Johnson
>
>
>
>
> |
> On Mon, Jul 12, 2010 at 4:46 PM, Santhosh Y <santhosh at softjin.com
> <mailto:santhosh at softjin.com>> wrote:
>
> Hi,
>
> How to see memory leaks in my Qt application. Would like to know
> the amount of memory leak in my application.
>
> I am working on Windows OS, using
>
> 1. Microsoft Visual Studio 2008
> Version 9.0.21022.8 RTM
> Microsoft .NET Framework
> Version 3.5 SP1
> 2. Qt 4.5.2 version
>
> 1. Any idea of how to run purify for a Qt application.
> 2. Any flags to be added to the project file / Visual studio for
> detecting memory leaks?
>
> Thanks in advance.
>
> Regards,
> Santhosh
>
> --
> ----------------------------------------------------
> Y Santhosh Kumar -
> Senior Software Engineer,
> SoftJin Technologies Pvt Ltd,
> www.softjin.com <http://www.softjin.com>
> ----------------------------------------------------
>
>
> Business Disclaimer
> ____________________________________________________________
> This e-mail message and any files transmitted with it are intended solely
> for the use of the individual or entity to which they are addressed. It
> may contain confidential, proprietary or legally privileged information.
> If you are not the intended recipient please be advised that you have
> received this message in error and any use is strictly prohibited. Please
> immediately delete it and all copies of it from your system, destroy any
> hard copies of it and notify the sender by return mail. You must not,
> directly or indirectly, use, disclose, distribute, print, or copy any part of
> this message if you are not the intended recipient.
> ___________________________________________________________
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
>
> --
> Johnson Ma
> ____________________________
> Keep it simple, stupid
--
----------------------------------------------------
Y Santhosh Kumar -
Senior Software Engineer,
SoftJin Technologies Pvt Ltd,
www.softjin.com
----------------------------------------------------
Business Disclaimer
____________________________________________________________
This e-mail message and any files transmitted with it are intended solely
for the use of the individual or entity to which they are addressed. It
may contain confidential, proprietary or legally privileged information.
If you are not the intended recipient please be advised that you have
received this message in error and any use is strictly prohibited. Please
immediately delete it and all copies of it from your system, destroy any
hard copies of it and notify the sender by return mail. You must not,
directly or indirectly, use, disclose, distribute, print, or copy any part of
this message if you are not the intended recipient.
___________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100712/d02a2fd3/attachment.html
More information about the Qt-interest-old
mailing list