How often should garbage collection be called? System.gc ()? I mean after what action?

  • four
    In a properly written program, never. He calls himself. And in the wrong written, the call will not give anything. And by the way, the call to System.gc() basically does not guarantee anything. - Vartlok
  • Yeah, he will call himself yes, but when there is no place to reserve memory. - Denis Kotlyarov

1 answer 1

System.gc () - does not call the garbage collector, but simply recommends the system to perform the build.

Moreover, the behavior of the garbage collector depends heavily on the strategies

My answer to the question: "how often?" - do not touch this method. Remember about it after you learn well how the virtual machine and the garbage collector work, not before. At this stage, you will not be able to benefit from this knowledge.

I recommend instead to deal with the causes that lead to leaks.

  • 2
    Ok, thanks, I will check my classes for leaks - Denis Kotlyarov