[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

GC in lambdas?

konsu

12/12/2005 6:30:00 PM

hello,

someone said in another conversation:

> also note that lambda will prevent __everything__ in it's scope from __ever__
> being garbage collected.

could someone please confirm this? i am also interested to know why GC
is so different in lambdas and whether the objects will be collected
when lambda itself goes out of scope?

thanks
konstantin

4 Answers

Edward Faulkner

12/12/2005 6:58:00 PM

0

On Tue, Dec 13, 2005 at 03:32:38AM +0900, ako... wrote:
> > also note that lambda will prevent __everything__ in it's scope from __ever__
> > being garbage collected.
>
> could someone please confirm this? i am also interested to know why GC
> is so different in lambdas and whether the objects will be collected
> when lambda itself goes out of scope?

There's nothing different about GC within lambdas. You simply need to
be aware of how lambdas work.

The lambda object needs to maintain references to everything that was
visible within the scope where it was created. As long as the lambda
object is alive, everything it references must also stay alive.

If you allow the lambda object to be garbage-collected, the things it
references will also be subject to garbage collection.

konsu

12/12/2005 7:03:00 PM

0

thank you. if lambda creates an object during its execution, and by the
time lambda finishes the object goes out of scope, is the object
garbage collected?

Eric Hodel

12/12/2005 7:15:00 PM

0

On Dec 12, 2005, at 11:07 AM, ako... wrote:

> thank you. if lambda creates an object during its execution, and by
> the
> time lambda finishes the object goes out of scope, is the object
> garbage collected?

The object is eligible for garbage collection. It may or may not be
collected immediately.

def inner
obj = Object.new # <-- object created
return lambda {} # <-- object held by lambda, not eligible for GC
end

def outer
my_proc = inner # <-- object still held by lambda, not eligible
for GC
return nil
end

outer # <-- proc eligible for GC, so created object eligible for GC

--
Eric Hodel - drbrain@segment7.net - http://se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




Fred C. Dobbs

6/3/2010 9:44:00 PM

0

On 6/3/2010 2:22 PM, Goo - Fuckwit David Harrison, The Coward -
attempted to bullshit:

> On Wed, 02 Jun 2010 Fred C. Dobbs pointed out:
>
>> Fuckwit does not care, in the *least*, about the animal having a
>> <gag-retch-hurl> "life of positive value".
>
>[snip goo nonsense]

It's not out of consideration for porcupines
that we don't raise them for food. It's because
they would be a pain in the ass to raise. We
don't raise cattle out of consideration for them
either, but because they're fairly easy to
raise.
Goo/Fuckwit David Harrison - Sep 26, 2005

I am not an extremist about it, and if I thought
that all of the animals I eat had terrible
lives, I would still eat meat. That is not
because I don't care about them at all, but I
would just ignore their suffering.
Goo/Fuckwit David Harrison - Nov 29, 1999

I would eat animals even if I thought that it was
cruel to them, and even if they gained nothing from
the deal. Is that what you want me to say? It is true.
But that doesn't mean that I can't still like the animals
also....
Goo/Fuckwit David Harrison - Sept 23, 1999

*NO* consideration for the animals, Goo - you only consider yourself.

You're defeated.