Wednesday, 30 July 2008

How EXACTLY does garbage collection work in Java?

gc -

main purpose: freeing memory from objects no longer referenced by the program

what does no longer referenced mean?

refcount==0

when is refcount==0? Most profilers use JVMPI or JVMTI (only in J2SE 5.0) to obtain reference counts of objects. MPI == machine profiler interface, MTI == machine tool interface (referring to the Java virtual machine of course).

secondary purpose: combat heap fragmentation (blocks of heap memory in-between blocks of live objects)

designer of each JVM must decide how to implement the gc-collected heap.

benefits:
1. productivity
2. security - prevent programmers from accidentally (or purposely) crashing the JVM by incorrectly freeing memory

No comments: