title: How does Java GC call finalize() method?
body: <p>As far as I understand, GC starts with some set of initial objects (stack, static objects) and recursively traverses it building a graph of reachable objects. Then it marks the memory taken by these objects as occupied and assumes all the rest of the memory free. </p>
  
  <p>But what if this 'free' memory contains an object with <code>finalize</code> method? GC has to call it, but I don't see how it can even know about objects that aren't reachable anymore.</p>
  
  <p>I suppose GC can keep track of all 'finalizable' objects while they are alive. If so, does having finalizable objects make garbage collecting more expensive even when they are still alive?</p>