From: Robert Klemme Date: 2008-08-01T17:34:10+09:00 Subject: Re: gc doesn't collect? On 1 Aug., 07:18, Roger Pack wrote: > Just to clear up confusion: > I believe that > > GC.start 'forces' a garbage collection, Yes, if forces a GC run. But I would not be so sure about whether it forces actual collection of all collectible instances. In other words: the GC is run but if it decides that there's nothing to collect yet, I won't collect anything even if there were objects that could be freed. > and that > do...end and > {...} scopes do indeed have their own scope and local variables, as > methods do. Yes. > interestingly, > > def go >   1.times { a = 'a'*1000}; You do not need the block here as your method provides one already. > end > go > 30.times { GC.start }; > print ObjectSpace.each_object{|o| print o} > > yields the same errant results.  I might look into it sometime.  Very > weird. > > Now for some questions: > > currently the GC marks live objects then sweeps to find any free > objects--except it doesn't actually free any objects that are free but > need finalization.  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? Which code did lead you to this conclusion? I am asking because finalizers are sometimes hard to get right. For example, you cannot define a finalizer with a block inside an instance method because the block will hold on to self and thus prevent collection. In that case you will see finalization only happen at program exit. Kind regards robert