How to clear screen

Is it possible to clear the screen of all items as I was doing it by object:removeSelf() but is this the only way to do it as I have a have allot of items to unload eg pictures, text and buttons when going to the main screen. It would be nice if there were something like *:removeSelf() can anybody help I have thought of something but corona seems to crash.

removeAll = display.getCurrentStage()

removeAll:removeSelf()

Main()

Thanks. [import]uid: 78144 topic_id: 13362 reply_id: 313362[/import]

Add all the items you want to remove to a group then remove and nil out that group [import]uid: 24641 topic_id: 13362 reply_id: 49026[/import]

How would this be done. Like this?:

group1 = display.newGroup()

group1:insert(???stuck here???)
then how would this be displayed if it were a picture and I take it that you cant just clear everything or can you? [import]uid: 78144 topic_id: 13362 reply_id: 49028[/import]

[lua]local group = display.newGroup()

local rect = display.newRect(100,100,100,100)
rect:setFillColor(255,255,255)
group:insert(rect)

–to remove the group, just call

group:removeSelf()

group = nil;[/lua] [import]uid: 24641 topic_id: 13362 reply_id: 49030[/import]

thanks Ill try that now. [import]uid: 78144 topic_id: 13362 reply_id: 49031[/import]

That didnt seem to work, some of it disappeared and there were no errors in terminal. The only way to make them re-appear was to comment out group1:insert(floor) and all the other items if I wanted them to appear. [import]uid: 78144 topic_id: 13362 reply_id: 49033[/import]

Hmm looks like you was right I just made a new app to test and yes that does work so sorry for saying it didn’t must have been a mistake I made. Also is this the only possible way can’t I just clear everything? [import]uid: 78144 topic_id: 13362 reply_id: 49034[/import]

This will remove all display objects from the stage. If you have object with event listeners, timers, etc. added to them and don’t clear them out before you do this, you’ll probably end up with huge memory leaks:

[lua]local stage = display.getCurrentStage()
while stage.numChildren > 0 do
local obj = stage[1]
obj:removeSelf()
obj = nil
end[/lua]

Darren [import]uid: 1294 topic_id: 13362 reply_id: 51840[/import]

Thanks for that Ludicrous Software it worked! :slight_smile: [import]uid: 78144 topic_id: 13362 reply_id: 52836[/import]