Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Garbage Collection

How do I disable garbage collection for a long running php cli script? I am handling unsetting of variables in the script.

like image 876
HyderA Avatar asked Jul 28 '11 11:07

HyderA


People also ask

How do I stop garbage collection?

A quick workaround is to disable the System. gc () and force a Full GC. The –XX:+DisableExplicitGC command can be passed as a java parameter that disables System. gc() for the JVM.

Can you turn off garbage collection in go?

You can disable GC and control when the GC has to be called in the runtime, by setting the environmental variable 'GOGC'. eg: GOGC=off disables the garbage collection.

What triggers garbage collection?

When a JVM runs out of space in the storage heap and is unable to allocate any more objects (an allocation failure), a garbage collection is triggered. The Garbage Collector cleans up objects in the storage heap that are no longer being referenced by applications and frees some of the space.

What is disable explicit GC?

The -Xdisableexplicitgc parameter allows the JVM to ignore these garbage collection suggestions. Typically, system administrators use this parameter in applications that show some benefit from its use. By default, calls to System. gc() trigger a garbage collection. Parent topic: Garbage Collector command-line options.


2 Answers

Unsetting variables does not free memory! It just removes the reference from the variable to the corresponding value. Once any value have a ref-count of 0 the GC collects the value and frees its allocated memory. If it would be possible to completely disable the GC you would break your interpreter (in best case): You will have many many unreferenced data in your memory, that will never get cleaned. Thats called "memory leak".

Is there garbage collection in PHP?

like image 123
KingCrunch Avatar answered Oct 13 '22 02:10

KingCrunch


In my case the issue was related with the Zend Server running as a cli -- It crashed often and randomly. On the internet I found about disabling the 'garbage collector'

To do so,

in php.ini

zend.enable_gc = Off

also, it can be changed directly in the cli

$ php -d zend.enable_gc=0 your_script.php
like image 21
user9869932 Avatar answered Oct 13 '22 03:10

user9869932