www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Minimise and collect by GC when OutOfMemory

reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
Would it be a good idea to call "collect" and "minimize" methods 
of core.memory.GC when OutOfMemory error is received FOR A LONG 
RUNNING PROGRAM? or there won't be any benefit of that?

Example program: A web server that allocates and releases memory 
from heap continuously.
Feb 25 2016
parent Chris Wright <dhasenan gmail.com> writes:
On Fri, 26 Feb 2016 05:47:08 +0000, tcak wrote:

 Would it be a good idea to call "collect" and "minimize" methods of
 core.memory.GC when OutOfMemory error is received FOR A LONG RUNNING
 PROGRAM? or there won't be any benefit of that?
 
 Example program: A web server that allocates and releases memory from
 heap continuously.
If OutOfMemoryError is thrown, the GC has already done everything it can to try to get more memory to use. If you find a case in which it helps to call GC.collect and GC.minimize, it's a bug that the GC threw an OutOfMemoryError. ...usually. If you are running on a 64-bit Linux system that has overcommit turned off and more address space than RAM + swap, you can get some mileage from GC.minimize() after OutOfMemoryError. Detecting this situation isn't necessarily easy, which is why the GC doesn't do it already.
Feb 26 2016