I have a java application that wants to invoke the system.gc(). Is it a reasonable method to release memory? or any other advice? Really appreciate!
Just stop referencing the variable. You don't need to invoke System#gc()
yourself. If the JVM is on an edge of an OutOfMemoryError
, it will certainly run the GC.
If stopping referencing the variables is not an option because you really need them, then you need to profile your application to fix/clean any memory leaks and/or just give JVM more memory at startup.
In Java it is not necessary to explicitly invoke garbage collection. It is done automatically by the virtual machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With