Implications of a #force_free method in Object?

From: Matthew Bloch <mattbee@...>
Date: 2002-08-19 11:29:05 UTC
List: ruby-core #326
Hello;

I'm wondering whether it would be a sensible idea to implement a #force_free 
method which would be a slightly more fine-grained way of controlling memory 
usage in Ruby programs.  There are a couple of occasions where I'm having to 
write:

  big_image = nil
  GC.start

to avoid getting a VM error from a 64MB Windows NT machine.  What I'd prefer 
to do, to avoid the garbage collection delay, is to be able to say:

  big_image.force_free

Which would simply free the memory used by that object and nilify the 
reference, no questions asked.  Obviously users of this method would have the 
burden of ensuring that no further references to this object exist, but the 
garbage collector could be used to spot such 'dangling reference' errors, and 
of course the runtime will fault it if such a reference is used.

The idea is a bit of a stop-gap, and could probably(?) be implemented as an 
optional extension rather than a necessarily core part of the interpreter.  
It would also allow the user to help the GC from pausing for too long (my 
favourite subject :-) ) by freeing objects he knows are not going to be used 
any more.  Any comments?

-- 
Matthew       > http://www.soup-kitchen.net/
              > ICQ 19482073

In This Thread

Prev Next