What happens when we explicitly call the Garbage collector method ?
I have come across a method gc()
which starts the 开发者_如何学Pythongarbage collection, how does this work?
It tells the Garbage collector to do a garbage collection run now.
Note: you can't force the VM into this, but in most circumstances the GC will be run
Here's a link to a blog post on how the Java Garbage Collector works
This question has been asked here
Also have a look at the arguments found here
Update to answer comment: The GC will not collect living objects, even if you're forcing a GC run. It will (mostly) do what it does when run automatically by the JVM
This method is but a hint to the VM that it could be a suitable time to perform a huge garbage collection. This method could have been useful with the first versions generations of GC when they used to do long pauses, but these times it's quite useless. You're not even guaranteed that there's an actual implementation behind the method :)
精彩评论