[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Userdata finalization order
- From: <jgiors@...>
- Date: Tue, 19 Oct 2010 01:02:26 -0700
> -------- Original Message --------
> Date: Mon, 18 Oct 2010 22:56:24 +0200
> From: Francesco Abbate <email@example.com>
> Subject: Re: Userdata finalization order
> To: Lua mailing list <firstname.lastname@example.org>
> Content-Type: text/plain; charset=ISO-8859-1
> 2010/10/18 Javier Guerra Giraldez <email@example.com>:
> > i can't think of an example where:
> > - A can be created before B
> > - but A depends on B (how did it exist before B, then?)
> > - you have to destroy A before B
> For example A is a plot and B is a line or a graphical elements. You
> create first the plot wichh is initially empty and then you add
> graphical elements like lines or circles or something else. Once you
> have added an element to the plot this latter store a *reference* to
> the element and it is therefore important to ensure that B (the
> element) is not collected as far as A (the plot) exists.
< ... SNIP ... >
By your description, it sounds like an "owner" pattern -- plot A owns
line B, and on the C++ side, B is deleted when A destructs, i.e. B would
not be deleted independently from A if you were writing the app in C++.
So, couldn't this problem be avoided by *not* having a finalizer for
i.e. the only way line B would be C++ destructed is when plot A's
destructor is called and it deletes all contained elements (one of which
is line B).
This would work on final cleanup and also if plot A were dereferenced
prior to final cleanup. You would still need to ensure no Lua code
dereferences line B independent of plot A.
Three Eyes Software