[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Userdata finalization order
- From: Francesco Abbate <francesco.bbt@...>
- Date: Mon, 18 Oct 2010 22:56:24 +0200
2010/10/18 Javier Guerra Giraldez <javier@guerrag.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.
But I can make to you a simple Lua example:
A = {}
B = { 'hello world' }
A[1] = B
A was created before B but now A contains a reference to B and Lua
will ensure that as far as A is still alive B will be not collected
because A contains a reference to B. And now just imagine the same
situations with C++ userdata instead of Lua objects... as you can see
it is really simple :-)
--
Francesco