Thank you Irv for your brilliant explanation... %-]
me was getting confused :)

----- Original Message -----
From: "Irv Kalb" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 18, 2001 6:21 PM
Subject: Re: <lingo-l> orphaned objects and memory space...


> Me, me, ... I'll volunteer.
>
> Unfortunately, your question "what happens if you try to reference
> props via the stored value in an object after you destroy the object"
> doesn't make sense.  There are two cases.
>
> Case 1)  (The typical case)  Assume a parent script like this:
>
> property prop1
> property prop2
>
> on new me, someParameter1, someParameter2
>    prop1 = someParameter1
>    prop2 = someParameter2
>    return me
> end
>
> You create the object like this:
>
>    someObjectReference = new(script "someParentScript", someValue,
> someOtherValue)  -- sets the refcount to 1
>
> Later, you destroy the object like this:
>
>   someObjectReference = VOID  -- the "ref count" goes down from 1 to 0.
>
> This means "there are no more variables that point to this block of
> memory".  Director's garbage collector then frees up the memory
> allocated for this object.  You no longer have any object reference
> to this object, so it is not possible for you to attempt to access
> any of its (former) properties.
>
>
> Case 2)  Lets say you have a parent script like this, in the new
> handler, you to store a copy of "me" into a property variable "pMe" -
> as Kerry originally suggested earler before recanting  :)
>
> -- someParentScript:
>
> property pMe
>
> on new me
>    pMe = me  -- this sets the "ref count" to 1
>    return me
> end
>
> And you create it with the following line
>
>    someObjectReference = new(script "someParentScript")  -- this sets
> the "ref count" to 2
>
>
> Then later, as you say, you destroy the object like this:
>
>    someObjectReference = VOID  -- in an attempt to the object
>
> But ... the object isn't destroyed because pMe still holds a
> reference to the object.  The ref count just goes from 2 down to 1.
>
> Now, unfortunately, you have an "orphaned" object.  There is this
> object lying around taking up memory, but you cannot get to it
> because there while there still is an object reference - there is no
> way you can get to it.
>
>
> Irv
>
> At 9:34 AM +0200 10/18/01, Chris Aernoudt wrote:
> >"me" is the same stuff as "this" in other proglangs -> pointer to the
> >encapsulating object, no?
> >So it's pretty useless to store it, because it won't change - I never
tried,
> >but I even think this might be a dangerous thing to do - what happens if
you
> >try to access props of an object via the stored value after the object
has
> >been destroyed?
> >Any volunteers? :)
> >
> >>  What Kerry says here is true.  But why would you do that?  Me is
> >>  always me whereever you use me in any method (handler) of the object.
> >  > There is no reason to have a property to keep another copy of me.
> >
>
> --
>
> Lingo / Director / Shockwave development for all occasions.
>
>    (Home-made Lingo cooked up fresh every day just for you.)
>
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
> email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming Lingo.  Thanks!]
>
>
>



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to