[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 'revoking' a userdata
- From: Ben Sunshine-Hill <sneftel@...>
- Date: Fri, 2 Sep 2005 15:56:32 -0700
On 9/2/05, DC <firstname.lastname@example.org> wrote:
> Is it possible for the c/c++ side to 'revoke' a userdata from a script?
> For example, an object which exists in one level of a game, but is no
> longer used or valid in the next level? If the script forgets to
> release the object it could persist.
Not really. What would happen to remaining references to the userdata?
If you just deleted the userdata, then accessing them would point into
unallocated memory. If you somehow magically nil'ed them, then they'd
be nil... and do you really want to check a userdata for being nil
every time you access it?
The solution here is to not forget to release the object. In any
garbage-collected language, the question of what is reachable and what
is not is paramount. If your userdata is not GCed, it means you have
told Lua, via a reference, that you don't want it to be GCed; that, of
course, is the bug.
> One solution has been to destroy the lua state when transitioning
> between levels. But, I want to be able to pass and maintain state.