[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Weak tables and userdata finalization
- From: Mark Hamburg <mark@...>
- Date: Sat, 3 Sep 2011 13:58:06 -0700
On Sep 2, 2011, at 12:11 PM, Gregory Bonik wrote:
> Hello Mark,
>
> It's a great coincidence: I had exactly the same problem yesterday. My
> program which uses similar cache just crashed randomly. The bug was very
> hard to reproduce and I spent the whole day tracking it down.
>
>> Now, I haven't seen this happening, but the above code snippet
>> certainly suggests that it's possible. Please tell me I've missed
>> something as opposed to just being extremely lucky...
>
> So yes, you were lucky :)
No, actually, as I noted in a follow up, it turns out that the case that really made me paranoid is taken care of. Direct caches of userdata get cleared when marked for finalization. It's just indirect caches that have problems and those need something else to keep the values alive.
The actual case we were dealing with:
View system userdata objects have Lua environments to couple them into the Lua logic. These point to other objects supplying values through a binding mechanism. In particular, we can have value suppliers supplying images which are themselves represented with userdata objects.
Collecting the view data preserves its environment which preserves the value supplier but doesn't keep the image being supplied from being finalized. Code comes along and constructs a new view which wants to find a supplier for a particular image and gets the cached which leads to it try to use a finalized image.
Mark