Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros and Cons of using SetProcessWorkingSetSize

I have an issue with memory management in my application. The application memory is growing up rapidly during the runtime. I'm using datasets in the disconnected mode. To overcome this issue, I'm flushing the DS frequently and also using SetProcessWorkingSetSize to manage the memory usage. It's working fine in my development computer. What are the pros and cons of using SetProcessWorkingSetSize?

like image 513
Shankar Avatar asked Nov 28 '11 06:11

Shankar


1 Answers

We have found out that, for a GUI application written in Delphi for Win32/Win64 or written in a similar way that uses large and heavy libraries on top of the Win32 API (GDI, etc), it is worth calling SetProcessWorkingSetSize once.

We call it with (... -1, -1) parameters, within a fraction of second after the application has fully opened and showed the main window to the user. In this case, the SetProcessWorkingSetSize(... -1, -1) releases lots of startup code that seem to not be needed any more. The memory quickly restores to about 1/3 of what it would have been without the SetProcessWorkingSetSize(... -1, -1), and does not grow more since then (unless the application allocates more memory). So we have effectively saved 2/3 of the memory of mostly startup code (loading and parsing of configuration files, initializing GUI, etc) that would not be needed to continue running the application.

If you have a GUI application, you may test on your own application the same way - just call SetProcessWorkingSetSize once and see how many memory have been released definitely.

Even for a server (service) application that don't have GUI - I think that calling SetProcessWorkingSetSize once after the server has fully loaded and initialized might have been useful.

like image 166
Maxim Masiutin Avatar answered Oct 01 '22 23:10

Maxim Masiutin