lua-users home
lua-l archive

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

Here is my analysis of what I think is causing this problem for us. We have
the following data structure:

    ud = userdata proxy object (pointer to native Objective-C object )
    mt = ud.metatable = metatable with per instance data
    imt = mt.imt = { backlink = ud }

ud becomes unreachable and hence so do my and imt.

We do __gc metamethod processing for ud which notices that ud's metatable
has per instance data. So, it saves that metatable into another table.

Somehow ud gets freed and the memory gets reallocated as a string before imt
gets collected. When the GC does a traverse table on imt it finds that
backlink is now listed as pointing to userdata in the node and a string in

I haven't traced things sufficiently to figure out the "somehow" step. I'm
hoping that by posting here, that will suggest something to the Lua team.

In the meantime, I should probably decide that creating new references to
data in __gc metamethods is a bad idea and look at other ways to achieve the
same effect.


on 12/9/04 3:08 PM, Mark Hamburg at wrote:

> on 12/9/04 11:25 AM, Roberto Ierusalimschy at wrote:
>>> 2. We've got a couple of cases where the tt value in a table entry
>>> doesn't match the tt value in the object.
>> Can that be a "dead" key? (That is, a key with a corresponding nil
>> value?)
> We're in a non-weak table (actually, it's a metatable). It has a string key
> that should be pointing to a full userdata value. The node in the table
> actually reports it as a full userdata. The value one finds by following the
> link from the node, however, is a string (and what appears to be a properly
> formed string).
> Mark