[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Nested userdata
- From: Wesley Smith <wesley.hoke@...>
- Date: Tue, 17 Feb 2009 13:21:05 -0800
This is not an easy problem, especially when it comes to managing the
lifetime of a nested object. What I've been doing is pushing the
nested udata on its parent creation and stuffing it in the parent's
env table. When a method asking for the nested udata is called, I
grab it from there.
The catch with this method comes when the parent is collected but the
nested udata is still valid. As I see it, there are 2 possible
1) Invalidate the boxed pointer the nested udata refers to (or some
equivalent marking of the memory as invalid) such that an error will
be thrown when used but will not cause a crash.
2) Have some kind of cyclic dependency such that the parent and child
will keep each other around as long as either one exists.