Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Created November 12, 2009 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probablycorey/233358 to your computer and use it in GitHub Desktop.
Save probablycorey/233358 to your computer and use it in GitHub Desktop.
-- Note: Lua Proxy Userdata is what holds the reference to the obj-c object
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment