From: Eric Hodel Date: 2008-08-02T03:43:37+09:00 Subject: Re: gc doesn't collect? On Aug 1, 2008, at 01:34 AM, Robert Klemme wrote: > On 1 Aug., 09:08, Eric Hodel wrote: >> $ ruby -v final.rb >> ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] >> 81660 created >> avr >> 81660 collected >> 81660 finalized >> $ ruby16 -v final.rb >> ruby 1.6.8 (2005-09-21) [i386-darwin9.4.0] >> 1117686 created >> 1117686 finalized >> omu >> 1117686 collected >> $ >> >>> It seems to only do finalizations when a user >>> explicitly calls GC.start, or when the program terminates. Is >>> there a >>> reason for this 'deferred_final_list' activity? >> >> This patch seems to restore 1.6 behavior: > > But does it also make finalization happen before program exit? (This > was Roger's main point IIRC.) Yes, but the suggested patch was not correct. See [ruby-core:18050] for the proper patch. The problem was that versions of 1.8 never ran finalizers unless you called GC.start or were exiting. > There was probably a good reason why > the order was reversed namely to make sure that objects were gone > before invoking their finalizers. No, finalizers were never called before collection. It looks like it was a simple oversight while fixing various SEGV bugs when doing evil things to ruby. > Actually this is how it is defined, > i.e. the finalizer is called after the object has vanished (see > Pickaxe for example). There was no code for running finalizers, except at exit or when calling GC.start.