lua-users home
lua-l archive

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


Sorry for the code formatting,
Here is a link to view the code more easily http://gist.github.com/233358

Corey

On Thu, Nov 12, 2009 at 2:07 PM, corey johnson <probablycorey@gmail.com> wrote:
> function dummyCode(array) -- array is an instance of an obj-c NSArray Object
>    local thing = NSObject:alloc():init() -- Assume the Lua Proxy
> Userdata for 'thing' is automatically put into the strong set
>    ... -- Misc Lua code. Assume the Lua garbage collector will be run
> during this code. Since 'thing' is
>        -- not being retained by any other obj-c code (its retain
> count is 1) it is removed from the strong set.
>    array:insertObject(thing) -- Now 'thing' has been retained by
> obj-c (its retain count is 2), but Lua has no way of knowing
>                                            -- it should be added back
> into the strong set.
>    thing = nil -- Now the Lua Proxy Userdata will be destroyed on the
> next garbage collection, yet the 'thing' obj-c object is still
>                    -- being used and will need the Lua Proxy Userdata
> end