[Qt-interest] Huge memory consumption

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jul 7 15:22:17 CEST 2010


James Matta wrote on Wednesday, July 07, 2010 12:26 PM:

> ...
> So my new question is this: Is it possible to free memory in the main
> program that was allocated in a plugin? 

As always "it depends": yes, if your plugin and main application share "the same address space": with Visual Studio there is a switch (somewhere in the project properties) which lets you define the "runtime environment".

Only if you set it to e.g. "Multithreaded DLL" (emphasis on "DLL" - the actual name might be different in Visual Studio) then you can

  delete theData;

in your main application code which you

  theData = new TheData();

in a plugin (= different DLL).

It is important that ALL DLLs you link to are compiled with the same runtime settings!

If you don't want to share the same adress space, then a typical pattern is that the plugin offers a "destroy" method:

void destroy(TheData *theData) {
  if (theData != 0) {
    delete theData;
  }
}

such that the object is deleted in the same address space in which it was created.


Note that I am not familiar with the corresponding g++ switches - if there are any at all related to that matter - but to my experience the "standard settings" (set by qmake) allow it to new/delete "across shared objects boundaries" without problems.


For Windows also refer to http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx and/or http://msdn.microsoft.com/en-us/library/ms235460.aspx ("Passing CRT Objects Across DLL Boundaries")


Does that help?

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list