Java garbage collector - When does it collect? -
what determines when garbage collector collects? happen after time or after amount of memory have been used up? or there other factors?
it runs when determines time run. common strategy in generational garbage collectors run collector when allocation of generation-0 memory fails. is, every time allocate small block of memory (big blocks typically placed directly "older" generations), system checks whether there's enough free space in gen-0 heap, , if there isn't, runs gc free space allocation succeed. old data moved gen-1 heap, , when space runs out there, gc runs collection on that, upgrading data has been there longest gen-2 heap, , on. gc doesn't "run". might run on gen-0 heap (and collections that), or might check every generation if has free lot of memory (which necessary rarely).
but far only strategy. concurrent gc runs in background, cleaning while program running. gc's might run part of every memory allocation. incremental collector might that, scanning few objects @ every memory allocation.
the entire point in garbage collector should thing without requiring input user. in general, can't, , shouldn't, predict when it'll run.
i believe suns jvm gained generational gc not long ago (v1.6 maybe? haven't coded java ages, not sure on this, remember being surprised not long ago, when 1 of selling points new version "a generational gc". not least because .net has had 1 since day 1.)
other jvm's of course free pick whichever strategy like.
edit: above part java , generational gc not true. see below more details:
the 1.0 , 1.1 virtual machines used mark-sweep collector, fragment heap after garbage collection. starting java 1.2, virtual machines switched generational collector, has better defragmentation behavior (see java theory , practice: garbage collection , performance).
so java has generational gc ages. what's new in java 6 garbage-first garbage collector (g1) available in java 6u14. according the article claiming release in 1.6.0_14: it not enabled default. parallel collector still default gc , efficient gc common household usage. g1 meant alternative concurrent collector. designed more predictable , enable fast allocation memory regions design.
Comments
Post a Comment