Removing a group and what's inside it.

local localGroup = display.newGroup(); local image = display.newImage("some\_image.png"); image.x, image.y = display.contentWidth/2, display.contentHeight/2; localGroup:insert(image); timer.performWithDelay(500, function() if(image)then                                             print("Not nil.");                                        else                                                print("Nil.");                                        end                             end, -1); local function deleteImage(e)     if(e.phase == "ended")then         localGroup:removeSelf();         localGroup = nil;     end end Runtime:addEventListener("touch", deleteImage);  

It’s said in some tutorials that an image inserted in a certain group is deleted when I remove that group. That’s not happening in the code above…

What’s wrong?

Thanks.

 

The image is deleted from the group (and removed from the display), but the image object is not “deleted” from memory. It is still there, and can be inserted into a different group if you want.

To delete it from memory you should set it to nil manually (after removing it from any display groups).

The image is deleted from the group (and removed from the display), but the image object is not “deleted” from memory. It is still there, and can be inserted into a different group if you want.

To delete it from memory you should set it to nil manually (after removing it from any display groups).