[Ruby] Ghetto
James Moore
banshee at banshee.com
Wed Jan 2 14:06:50 PST 2008
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
More information about the Ruby
mailing list