In what cases is it necessary to call Garbage Collector manually through the System.gc () method in JAVA?

-3

I do not know if in complex programs like IDEs: IntelliJ, eclipse, netbeans among others occupy it at some point to more efficiently release system resources manually (speaking clearly of their source code of those IDEs and not at the moment of program on them)

For example, when destroying an object giving it a null value, followed by invoking the System.gc () method would be a good practice?

    
asked by Missionary robot Robot 20.11.2018 в 15:52
source

1 answer

2

I can think of two cases where you may need to force 1 garbage collection:

  • In a test environment where you are looking for memory leaks (memory leaks). Just before checking how much memory your application is using, it can be useful for the JVM to clean up. In general, the JVM itself usually chooses the appropriate time to call the GC, so your program attempts to force the call is usually unnecessary.

  • On a system in real-time hard : This is a very unlikely case since Java is not meant to work in these environments, but JVM implementations have been created for real-time systems . When you make a call to the GC, the JVM freezes the execution of the application, examines it, frees the unused memory and unfreezes the execution . If the GC is executed just when your application should receive a call that can not wait (the GC can freeze the system for a few milliseconds), the application may fail in its task. In these JVM you can request a pass from the GC to make sure that at the right moment your system is active .

1 A call to System.gc () does not ensure that the GC is executed, it is a suggestion to the JVM, which it can ignore (or not). It depends entirely on the implementation of it.

    
answered by 20.11.2018 / 16:40
source