object doesn't get removed

Why object doesn’t get removed? It stays even after 700ms

local beam = display.newRect( display.contentCenterX + 50, display.contentCenterY - 130, 15, 100 )
              --beam.fill = {1,0,0}
              --beam.alpha = 0
              beam.objType = "beam"
              beam.isBullet = true
              beam.isSensor = true

              timer.performWithDelay(700, function()

You gotta put in the variable name in display.remove, so without the quotation marks


1 Like

yeah, that was my mistake.
And one more thing:

after I removed quotation marks beam and other object didn’t collide
then I added print(“a”) into collision function for debugging and then collision fixed…

But now I am writing this post and experimenting with print() and it doesn’t work again…
Even with print(“a”) :confused:

It is so weird and confusing

To properly remove a display object, you need to both remove it and set it to nil, i.e.

local beam = display.newRect( 0, 0 100, 100 )
beam = nil

If you don’t set it to nil, then it’ll still remain in the memory.

Also, adding those prints while debugging only shows how far you get until a crash occurs. Without seeing your code, we can only guess as to why it crashes. If you need help with that, then you should open a new thread and share a small sample project that demonstrates your issue.