PDA

View Full Version : Memory issue when close QMdiSubWindow



seauniv
11th December 2014, 02:34
Hi all,

We have a MDI application, using QMdiSubWindow as tabbed windows. As shown in htop, each QMdiSubWindow (and its internal widget with data) will consume 8M memory.
So, when I create more and more QMdiSubWindow, say 10, the total memory consumed by the application will gradually increase.
That's OK. The problem is when I close the existing QMdiSubWindow, the memory won't decrease.

We have set WA_DeleteOnClose attribute to delete QMdiSubWindow when closing.
setAttribute(Qt::WA_DeleteOnClose);

I know memory allocated to a process is not generally freed to the operating system immediately an object is deleted. Is there any suggestions to decrease total memory as soon as possible?
I tried Google Chrome, it will free memory to operating system in a short time when close existing tabs.

ChrisW67
11th December 2014, 20:13
The memory allocator is linked into your program, usually from glibc on Linux. In general it will hold on to all memory allocated to the process, even when freed, and satisify future requests from that pool. The operating system will only try to reclaim allocated but unused memory from processes if it needs to satisfy another request and cannot. In your case, the memory released by closing a tab should be used when you open the next. The precise dynamics of this are driven by exactly how your program allocates and deallocates memory.

Chrome almost certainly has a customised/optimised memory allocator that deliberately manages the interaction with the operating system's free list by preallocating memory into the process in large chunks. You can provide your own memory allocator but it is usually unnecessary.

See
http://stackoverflow.com/questions/12178961/if-when-does-the-does-deallocated-heap-memory-get-reclaimed
http://en.m.wikipedia.org/wiki/Sbrk

seauniv
12th December 2014, 01:21
Thanks very much!:)