I'm missing why do you want to remove your sprite (which is not a child of stage) from stage.
you remove a sprite from its parent: if its parent is stage, you remove it from stage, if its parent is another sprite you remove it from the other sprite.
you can also try:
if sprite then
sprite:removeFromParent()
sprite =nilend
you may be missing that there are two parallel structures for your objects, one is the hierarchy how they are added to the stage, the other is based on object oriented programming, and is not related to stage hierarchy, objects can exist without being added to the stage or whatever. in this hierarchy one object (or rather table in case of lua) can be a subtable of another, like obj1=Sprite.new() obj1.obj2=Sprite.new() then you have two objects, obj1.obj2 is a subtable of obj1, but you can still build the stage hierarchy in any other way. thus in the stage it's possible to have stage:addChild(obj1.obj2) and obj1.obj2:addChild(obj1) and so in the stage obj1 is the child of obj1.obj2.
also if you don't add them to the stage, they still exist in the memory until you e.g. nil them e.g. obj1.obj2=nil will release obj1.obj2, but e.g. obj1=nil will release both of them as nothing will reference obj1.obj2 anymore).
Comments
where child is the sprite you are looking for
stage:addChild(sprite)
stage:removeChild(sprite)
or its take memories?
If it is because you can't access it, maybe the reason is because it is referenced as local, and stage is missing the reference to sprite.
you remove a sprite from its parent:
if its parent is stage, you remove it from stage,
if its parent is another sprite you remove it from the other sprite.
you can also try:
obj1=Sprite.new()
obj1.obj2=Sprite.new()
then you have two objects, obj1.obj2 is a subtable of obj1, but you can still build the stage hierarchy in any other way. thus in the stage it's possible to have
stage:addChild(obj1.obj2)
and obj1.obj2:addChild(obj1) and so in the stage obj1 is the child of obj1.obj2.
also if you don't add them to the stage, they still exist in the memory until you e.g. nil them e.g. obj1.obj2=nil will release obj1.obj2, but e.g. obj1=nil will release both of them as nothing will reference obj1.obj2 anymore).
Fragmenter - animated loop machine and IKONOMIKON - the memory game