[Ruby] Ghetto
John Barnette
jbarnette at gmail.com
Wed Jan 2 15:36:26 PST 2008
It seems like things that somehow slither into the global scope never
get GC'd, even if there are no explicit references to 'em. Lazylist,
run this snippet according to the comments in it: Are your results the
same as mine? :)
http://pastie.caboo.se/134220
~ j. // Time to start reading Ruby internals.
On Jan 2, 2008 2:06 PM, James Moore <banshee at banshee.com> wrote:
> On Jan 2, 2008 1:46 PM, Aaron Patterson <aaron.patterson at gmail.com> wrote:
> > This code is a ghetto:
> >
> > class User; end
> > User.new
> >
> > GC.start
> > user = nil
> > ObjectSpace.each_object do |object|
> > user = object if object.class.to_s == 'User'
> > end
> > p user
> >
> > Anyone know why this finds a user? I'm at a loss! :-(
> >
> > --
> > Aaron Patterson
> > http://tenderlovemaking.com/
>
> I don't think there's any assurance that an object will be garbage
> collected at any given point in time.
>
> GC.start isn't going to make sure that anything that isn't referenced
> will be GC'ed. (And AFAIK, there's no way to get that behavior in MRI
> 1.8.)
>
> - James
>
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>
More information about the Ruby
mailing list