PDA

View Full Version : Qt dll + memory leak



Fastman
1st August 2009, 14:42
for example:



//Qt dll - H
class DLL_EXPORT ScriptEngine
{
public:
~DLL() {}
DLL() {}

bool SomeFunction(LPCTSTR);

};




//Qt dll - CPP
DLL::SomeFunction(LPCTSTR cStr);
{
//If this cause any Qt function or initialize Qt class
//in the Win32 application, I get a memory leak!
}



Win 32 MFC project:
(All are linked without any problem)


...
#include "dll.h"
#pragma comment(lib,"../debug/dll.lib")

....

DLL *a;
a = new DLL;

a->SomeFunction(...);

if (a != NULL)
delete a;



After closing the application window output MSVS see:
for example:


Detected memory leaks!
Dumping objects ->
{186} normal block at 0x007B8750, 24 bytes long.
Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
{185} normal block at 0x007B86A8, 104 bytes long.
Data: < #g` { U2g> F4 B1 23 67 60 86 7B 00 00 00 00 00 E8 55 32 67
{184} normal block at 0x007B8660, 8 bytes long.
Data: < #g { > 00 B2 23 67 A8 86 7B 00
{183} normal block at 0x007B8608, 24 bytes long.
Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
{182} normal block at 0x007B85B0, 24 bytes long.
Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
{181} normal block at 0x007B8538, 56 bytes long.
Data: < ` { > 01 00 00 00 60 86 7B 00 00 CD CD CD 00 00 00 00
Object dump complete.
The program '[4884] Test.exe: Native' has exited with code 0 (0x0).

caduel
1st August 2009, 15:45
Well, it happens that Qt might initialize some global stuff that is not released when you delete your class.
Unloading the .dll might cause that memory to be freed (or not).

Fastman
1st August 2009, 16:16
Well, it happens that Qt might initialize some global stuff that is not released when you delete your class.
Unloading the .dll might cause that memory to be freed (or not).

And how to unload all that was initialized in the library prior to her discharge?
In fact, a memory leak is even simple initialization QString c and given a line of any text.

Fastman
2nd August 2009, 14:28
After the experiments - found that the memory leak only occurs in debug mode. In the release - this is not. But the same should not be!
What can recommend?