in reply to Controlling the order of object destruction

I am not sure (but could be wrong) that your assertion about LIFO order is correct. If I remember correctly, all that is guaranteed is that an object may (note that I didn't say will) only be destroyed when there is no longer a reference pointing to it.

This is why objects with circular references need to use special tricks (like weaken or similar) to free memory.

--MidLifeXis

  • Comment on Re: Controlling the order of object destruction

Replies are listed 'Best First'.
Re^2: Controlling the order of object destruction
by metaperl (Curate) on Dec 10, 2009 at 17:17 UTC
    I am not sure (but could be wrong)
    yes, I'm not sure either. I appreciate your input. I definitely want a reference in the docs if possible.
    all that is guaranteed is that an object may (note that I didn't say will) only be destroyed when there is no longer a reference pointing to it.
    yes, that's why I used braces in the second part of the code - to control the order of reference loss.

      Neither MidLifeXis nor ikegami's statements seem to imply a guarantee that an object will be immediately be destroyed when the last reference goes away though.

      So even in your second case it would be in theory possible that the objects are freed in a different order than what you're expecting.

      So there still two questions that might be interesting: 1) does the spec mandate object destruction as soon as there's no reference left; and 2) do all current implementations (including Activestate) behave the same way?