When is a group really deleted?

function popupGroup:cleanUp() -- popupGroup is a displayGroup with two objects within (a rectangle and an image). popupGroup[1]:removeSelf() popupGroup[1] = nil popupGroup[2]:removeSelf() popupGroup[2] = nil popupGroup = nil

That sounds like it should either outright delete or at least nil out popupGroup. But am I correct in thinking that if any other code references it, it’s still there? say:

someButton:addEventListener("tap", PressPop)

I ask because in this event listener, the variable can only be nil once. Even if it says nil, it’s still not.

local PressPop = function(event) if event.phase == began then if myPopup ~= nil then print("Removing the popup!") myPopup:cleanUp() end end end

^^ In that example, the if statement only works once. Run the cleanUp code, and myPopup ~= nil is still true, even though I explicitly tell it that myPopup = nil in the cleanUp code. print reveals an 8 digit table code.

(I was hoping to just say if myPopup == nil or if myPopup ~= nil.)

Is there a more reliable way to delete objects? Or, if not, is there a better way to detect whether a variable exists (and how to delete it?) Or do I basically have to give up on existance detection and use a variable to store whether there should or shouldn’t be a popup? [import]uid: 41884 topic_id: 15229 reply_id: 315229[/import]

Well, on the one hand, I fixed the problem. On the other, I’m still concerned that this approach is maybe unorthodox or just overkill for what I’m doing. Thoughts if you’ve got 'em?

local PressPop = function(event) -- if event.phase == began then if event.target == cancelButton then if myPopup ~= nil then myPopup:cleanUp() -- erases all of the table content myPopup = nil -- tell the root table to be garbage collectgarbage("collect") -- send in the garbage trucks else print("There's no popup to cancel!") end end end end

The basic theory, for anyone new to this stuff like me, is that you have to:

  1. Clear out the table like you’re moving downtown
  2. Set the table variable to [lua]nil[/lua]
  3. Call garbage collection for a pickup (which will grab nil entries)

I swear I had read somewhere that setting to nil was about as good as it gets for deleting stuff at runtime, but you really do need to call garbage collection or stuff will hang around like it’s a Quebec sidewalk. This API page is vaguely helpful in this regard.

Ansca team, is there any particular reason why collectGarbage() is not on the API page? (When I was using search I could only find thread references - no specific API page…) [import]uid: 41884 topic_id: 15229 reply_id: 56283[/import]