View Full Version : How to release memory before Qt's Program finished ?

2nd December 2011, 10:18
Hi all ,

i'm writing a really big(fat?) program ,
there's lots of function on this program ,
and i use a lot of widget / dialog box ...something like that ,
and i also add Qt::WA_DeleteOnClose ,
but seems like Qt will not release ram space back to system?

i've test to open all my function and close ,
at first my program run , it only take 1.7% of memory
after all the function open once , it take 2.2% ~ 2.3% of memory
and it keep in 2.2%~2.3% of memory usage , no matter the function opend twice or more times

Is there anyway to release Qt's memory back to system ?

thanks for any reply~

2nd December 2011, 13:00
Actually memory released on program exit by OS itself. But if you worry about memory usage during program work, then it seems you have memory leaks inside your code.

2nd December 2011, 14:17
don't worry. Just because you "delete" an object doens't mean the memory gets back to the operating system. your programm might keep this part reserved for future allocations.

2nd December 2011, 14:30

That is, the OS keep some memory for reallocations, it is for "increase" agility when doing that...
On Windows-based environment you can use the SetProcessWorkingSetSize, from Windows API... Sending the last two parameters a -1.
It will "removes as many pages as possible from the working set of the specified process." - http://msdn.microsoft.com/en-us/library/windows/desktop/ms686234%28v=vs.85%29.aspx.
This will not release any memory allocated by the program itself, just what OS think will be allocated again...

I don't know if there is a POSIX equivalent...


5th December 2011, 01:20
Thanks for all your reply ,
i will try to find if there is any command like "SetProcessWorkingSetSize" under linux ,
and check my program if there is any memory leaks .:)