[Resolved] How can i implement a lock/semaphore

local grp = display.newGroup

local function destroy(obj)
obj:removeSelf()
obj = nil
end
destroy(grp)

In such an example, how could I go about setting grp to nil inside of that destroy function instead of just the local reference to it from the function? [import]uid: 121569 topic_id: 32304 reply_id: 128642[/import]

You can’t and you don’t. Not sure if you are used to C++, but it’d be like trying to redirect all pointers to an object to point somewhere else. The amount of extra processing and memory that would be required for each reference to each object to know about all others is just not worth it.

EDIT: In LUA, you still can solve your question, by accessing grp(an upvalue in LUA), instead of obj, but that merely fixes the example, but not actually a valid solution to cleaning up lingering references.

Often times, you simply use a system on the object to get it’s state.
For Example:

function \_G.destroyDisplayObject(obj)  
 if obj and obj.removeSelf and not obj.destroyed then --destroyed boolean lets you check if an object is destroyed  
 obj:removeSelf()  
 obj.destroyed = true  
 end  
end  

This way, you can use obj.destroyed to detect if the object is destroyed or not(so long as you use this destroy function and not removeSelf directly). Other options include keeping a table of active references (cleaning the out on destruction), replacing the removeSelf function to something else on destruction(as above), or having a main reference that gets destroyed, and using weak references and get accessors so you can detect if they are cleaned up at any time(potentially unsafe since a removeSelf, and garbage collect occur at different times). [import]uid: 134101 topic_id: 32304 reply_id: 128643[/import]

Well thanks a ton Ntero,

I didn’t know that setting that reference to nil didn’t nil out the actual object, and after I accounted for that all of my problems went away

[import]uid: 121569 topic_id: 32304 reply_id: 128655[/import]