Project

General

Profile

Release Memory used by Widgets

Added by Jason D 8 months ago

Hi,

I did a test as below,

  1. Add 10000 elements to page, I can see that memory size has been increased around 15Mb (with Mac activity monitor Private Memory Size)
  2. Remove all those 10000 elements with parent -> clear() method, the memory size has been decreased by less than 5MB.
  3. Recheck memory usage after 10 minutes, the memory size didn't drop.
  4. Add 10000 elements to page, again I can see that memory size has been increased around 13Mb
  5. Remove all those 10000 elements with parent -> clear() method, the memory size has been decreased by less than 3MB.
  6. Recheck memory usage after 10 minutes, the memory size didn't drop.

With this test result, it seems the memory cannot fully released by removing them, what d

My project has serious concerns over memory usage, any help on identifying the cause or releasing the memory size is very much appreciated, thanks in advance.

My test code:

button1 -> clicked().connect([ = ] {
for (int i = 0; i < 10000; i++) {
parent -> addWidget(Wt::cpp14::make_unique < Wt::WPushButton > ());
}
});

button2 -> clicked().connect([ = ] { parent -> clear(); });

Best Regards,
Jason Dong


Replies (4)

RE: Release Memory used by Widgets - Added by Plug Gulp 8 months ago

Would you be able to run valgrind[0] on your program? What does it report?

[0] https://valgrind.org

RE: Release Memory used by Widgets - Added by Jason D 8 months ago

Valgrind is not supported on my MacOC Monterey, tried 'leaks' but nothing detected.

RE: Release Memory used by Widgets - Added by Roel Standaert 8 months ago

Perhaps what you're observing is not an actual leak in the program code, but the memory allocator not giving back the freed memory to the operating system.

You could use Valgrind's Massif heap profiler to see the actual memory usage by the application code over time on platforms where it is supported.

I think on a Mac you could use Instruments?

    (1-4/4)