How to make an object to be removed from the screen

When the user clicks an arrow icon in my app, a sub menu appears (see code below only with the background to facilitate the understanding). If user clicks the arrow again, the menu must be removed (I don’t want to make is invisible to avoid memory usage). How can I do that?

local arrow = “close”
local function onFullMenu()
if (arrow==“close”) then
–Opens menu
local back = display.newRect(0,0,100,100)
back:setFillColor(10,101,10)
menu:insert(back)
arrow = “open”
else
arrow=“close”
menu:remove(back) --Here i want to remove the “back” from the screen but it is not working
end if

local menu = display.newGroup()
arrowDownButton = ui.newButton{
default = “butArrowDown.png”,
over = “butArrowDownRoll.png”,
onPress = onFullMenu
}
menu:insert(arrowDownButton) [import]uid: 4883 topic_id: 929 reply_id: 300929[/import]

When you make an object invisible, it does not effect memory. In fact, it is better for the framerate.
You can also set its alpha value to zero, that has the same effect.

menu:remove(back)

does what it isays, it deletes the child BACK from the group MENU.

Btw. there is no endif in LUA. All structure and loop commands end with an END. [import]uid: 5712 topic_id: 929 reply_id: 2206[/import]

Hi d3mac123,

I was looking at your code above again and it looks incomplete to me. Besides the END IF I mentioned, it looks either there is an END missing for the function, or your create a local MENU inside the function, after you reference to MENU in the code above it.

Michael [import]uid: 5712 topic_id: 929 reply_id: 2207[/import]