There is no way to tell when the garbage collector will actually execute, in fact it might never execute at all.When you invoke the method system.gc(), all you are doing is
suggesting,humbly so, that you would very much appreciate if the garbage collector was run.Whether and when it actually gets to run is not anything you can control.Usually the gc will run as response to a runtime request from the VM, which often times is a consequence of your program exhausting all its memory on the heap, so much so that some resources need to be released and memory be made available to your program.The exact implementation of garbage collection is platform dependent and its behaviour in general is not guaranteed.
Herbert