lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks... I did have a handle on that, I should have been more clear.  The
child state definitely got GCed as you said.

I guess what I'm confused about is this... should doing my
luaL_ref(childState, LUA_REGISTRYINDEX) with the entry point be enough to
prevent GCing of the childState?  Since the reference is "within itself",
does that count?  It seems so because my memory usage keeps creeping up if I
don't luaL_unref().  Yet... sometimes one get's GC'd and causes that crash.

I guess I'm just trying to reconcile those two seemingly contradictory

-----Original Message-----
[] On Behalf Of Jamie Webb
Sent: Sunday, September 12, 2004 8:56 PM
To: Lua list
Subject: Re: Child states and garbage collection

On Sun, Sep 12, 2004 at 07:43:35PM -0500, Matthew Harmon wrote:
> EXCEPT... on occasion, the script seems to be GC'd before I do the unref()
> and it crashes when I get to the unref().  Can anybody give me a hint
> this.  Am I approaching this totally wrong?

Calling luaL_unref() with a bad reference should not cause a crash. I
suspect that what has actually happened is that your child state
itself has been GCed. You need to make sure a reference to the state
exists, e.g. in the registry, until you have finished with it.

> I managed to solve the problem by creating my references in the "master"
> state, but I'd still like to understand what is going on under the hood.

References are stored in the registry, which is shared between a
'master' and all its children. So, this change is probably just
working around the actual problem by avoiding referring to the
deceased child.

-- Jamie Webb