Issues when removing groups [maybe other display objects?]

Hello

In our projects, which have some quite complicated structures of gorups, we very often have checks to see if a group still exists or not [for example when downloading images from the internet, we check if the group we want to insert it into still exists].

Anyway… we perform the check like this:

if group and group.removeSelf then ... end

It worked nicely until we hit a problem yesterday and traced it back to a group, which parent is removed, but group.removeSelf function still exists. Cool huh?

We checked other properties, but numChildren, insert, proxy, class were removed. However removeSelf lingers on.

I believe I took the idea of checking if <object> and <object.removeSelf> then

to see if the display object was not removed from one of the Corona devs.

The other question is what happened that this was not removed? In 99% of scenarios it does.

Thanks

Krystian

Don’t know, but I would check the .parent to see if it really does exist.

However, how are you even checking if it still exists if you have removed it? Remove a display group and you should have expunged all references to it and therefore not be able to check it’s existence. It would only continue existing if you have either not removed all the references to it or the garbage collector simply hasn’t had a chance to clean it up yet.

Hello Horace,

well yeah, in this case we have resolved the problem by checking the parent.

Among multiple of cases, here’s one that we have:

In certain places we display facebook avatars, in order to display them, we download the json descriptor, once we get some info out of it, and when we know that fb user has an avatar, we download it, once downloaded we display it on screen. But as you can see, this process can take quite a few seconds, so the user might have closed that screen already.

So in this case, whether we like it or not, the reference to the group that we are going to insert avatar into needs to be exposed somehow to the listener. So I want to use that to determine whether avatar is still to be inserted or not. 

The only other ways I think it would be possible would be:

  • to have a state variable (flag) and I think using such flags in this case would be stupid [we already have the object in question, we should be able to know what it’s state is without adding some dubious variables… things go wrong too often because of using them]

  • to perform network.cancel on the avatar/descriptor requests - but I don’t want to do that since I want to have a cache of avatars, so we can display them immediately the next time they are required.

Anyway… we worked around the problem using .parent property, but I still didn’t figure out why the removeSelf function remained on the object.

Don’t know, but I would check the .parent to see if it really does exist.

However, how are you even checking if it still exists if you have removed it? Remove a display group and you should have expunged all references to it and therefore not be able to check it’s existence. It would only continue existing if you have either not removed all the references to it or the garbage collector simply hasn’t had a chance to clean it up yet.

Hello Horace,

well yeah, in this case we have resolved the problem by checking the parent.

Among multiple of cases, here’s one that we have:

In certain places we display facebook avatars, in order to display them, we download the json descriptor, once we get some info out of it, and when we know that fb user has an avatar, we download it, once downloaded we display it on screen. But as you can see, this process can take quite a few seconds, so the user might have closed that screen already.

So in this case, whether we like it or not, the reference to the group that we are going to insert avatar into needs to be exposed somehow to the listener. So I want to use that to determine whether avatar is still to be inserted or not. 

The only other ways I think it would be possible would be:

  • to have a state variable (flag) and I think using such flags in this case would be stupid [we already have the object in question, we should be able to know what it’s state is without adding some dubious variables… things go wrong too often because of using them]

  • to perform network.cancel on the avatar/descriptor requests - but I don’t want to do that since I want to have a cache of avatars, so we can display them immediately the next time they are required.

Anyway… we worked around the problem using .parent property, but I still didn’t figure out why the removeSelf function remained on the object.