garbage collecting CLI command?

Ulti

Member
Is there a CLi command for garbage collecting, the "Collect Garbage" icon on the top right in Mafia which results in something like "Reclaimed 42197 KB of memory". I'd like to be able to clear the garbage when memory is the lowest when the CLI is responding to scripts through the relay browser, but not responding to the button in Mafia.
 
Last edited:

lostcalpolydude

Developer
Staff member
The command is gc. As xKiv alluded to, it won't actually run until the CLI finishes handling the other scripts that are keeping the button from being responsive.
 

xKiv

Active member
What I meant is that triggering garbage collection won't usually free any memory, as far as the OS is concerned. Java keeps it allocated for itself. There are some ways in hich java can decide to grow/shrink the heap (with some default+configurable minimum and maximum), but those don't even necessarily trigger on every GC, and you are likely to be as low as possible anyway.
And inside java itself, triggering GC shouldn't do anything interesting too - you are doing work that would have been done anyway, some time later.
The only reason I have ever found to trigger GC programatically is, when I want to measure memory actually allocated by "live" objects in the application - if you GC twice (which *should* trigger a full sweep), there will be no dead objects left in the heap, so you can "Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()" (you need to take this difference exactly because JVM might have decided to change total heap size - I remember a colleague being bewildered by free memory "going up" after allocating some objects ...).
 
Top