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]