java - Why this happens in garbage collection injava -
as know when run garbage collection using system.gc() method collect unused , undestroyed objects heap , clean it. when run system.gc(); memory of jvm should increased. in below code when run it, result confusing me.
runtime rs = runtime.getruntime(); system.out.println("free memory in jvm before garbage collection = " + rs.freememory()); rs.gc(); system.out.println("free memory in jvm after garbage collection = " + rs.freememory());
the output
free memory in jvm before garbage collection = 12184624 free memory in jvm after garbage collection = 12184360
see before value greater after value.
please correct me if in wrong concept or explain me why happen.
thank you.
calling garbage collection in java merely suggestion jvm. way garbage collected technically 100% out of control. calling system.gc() politely suggests trash should taken out, java within rights ignore disobedient child.
although ask, won't , can't rely on it.
Comments
Post a Comment