You will need to set the variables for each button to nil in order to remove the buttons from memory, so your first code block is better.
An improvement on that is to update each removal to:
button1 = display.remove( button1 )
because .remove() doesn’t return anything.
Going a step further, if you put all the buttons into a display group and reference them on that group, you won’t have to remove them individually and you will be able to use your second code block instead. This is because, to properly remove a display object from memory, you need to remove the display component (the image) and the variable reference.
So, if you create a group, then create the buttons and make them attached to that group, you can remove it and everything under it at once. Having separate, globally visible variables for display objects stops you from doing that.
Eg:
-- create the buttons and their parent group local btnGroup = display.newGroup() btnGroup.btn1 = display.newImage( "button1.png" ) btnGroup.btn2 = display.newImage( "button2.png" ) -- remove the button group and all the buttons in it btnGroup = display.remove( btnGroup )