[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Userdata finalization order
- From: Lavergne Thomas <thomas.lavergne@...>
- Date: Wed, 20 Oct 2010 15:28:30 +0200
Le 20 oct. 2010 à 09:17, Francesco Abbate a écrit :
> --------------
> a = fxline(sin, 0, 2*pi) -- create a line
> b = plot('Test plot')
> -- add the line a to plot b as a dashed line
> b:addline(a, 'red', {{'dash', 7,3,3,3}})
> b:show()
> --------------
>
> What's wrong about that ?
>
Nothing but you have to tell the GC that "b" keep a reference on "a". You can do this a lot of way.
A simple one where you will see the "reference" explicitly is to do a <luaL_ref> in the addline method and keep in "b" the returned int, this will tell the GC that you are keeping a reference on this object. Next in the __gc of "b" you just do a <luaL_unref> with the kept int to tell the GC that you release this reference.
This will make your code OK, as the reference is not stored in the object itself but in the registry, so "a" and "b" will not be collected in the same cycle and so the order will be always respected.
- References:
- Userdata finalization order, Petri Häkkinen
- Re: Userdata finalization order, Wesley Smith
- Re: Userdata finalization order, Petri Häkkinen
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Javier Guerra Giraldez
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Roberto Ierusalimschy
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Javier Guerra Giraldez
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Wesley Smith
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Wesley Smith
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Wesley Smith
- Re: Userdata finalization order, Francesco Abbate
- Re: Userdata finalization order, Francesco Abbate