Loop through and remove display objects when change scene?

Hey all, I have an array Items={}  that I use to declare variables and display objects in my scene.

When I leave the scene, I want to make sure I clean up and remove every item in that Items{} array but I need help determining if each item when I iterate through the table is either a display object (image, rectangle, etc.) or just a simple variable and then executing removeSelf() on the display object.

I thought I had seen this somewhere before but I’m struggling locating it.

For example:

for p,v in pairs( Items ) do

   if Items[p] IS A DISPLAY OBJECT then <-- what do I check for here??

         Items[p]:removeSelf()

   end

   Items[p]=nil

end

FYI, I came up with this in testing, but I feel there might be a more efficient way:

for p,v in pairs( Items ) do

    if type(Items[p])==“table” then

        if Items[p].removeSelf~=nil then

            display.remove( Items[p] )

        end

    end

    Items[p] = nil

end

If you add the display objects to scene.view, you don’t need to remove and nil them yourself. 

I thought display objects in arrays/tables still needed to be removed explicitly.  I’m having images in my Items array stick around on scene reloads for some odd reason.

As long as the table is local that will be removed also. 

Are you removing the scene from memory when you move to another one?

FYI, I came up with this in testing, but I feel there might be a more efficient way:

for p,v in pairs( Items ) do

    if type(Items[p])==“table” then

        if Items[p].removeSelf~=nil then

            display.remove( Items[p] )

        end

    end

    Items[p] = nil

end

If you add the display objects to scene.view, you don’t need to remove and nil them yourself. 

I thought display objects in arrays/tables still needed to be removed explicitly.  I’m having images in my Items array stick around on scene reloads for some odd reason.

As long as the table is local that will be removed also. 

Are you removing the scene from memory when you move to another one?