All that cleanup....

I am a bit confused and thinking all the time about all that cleanup you have to do when
changing a scene/level. I am coming from some other programming languages and 3D engines
but had never have to do such a cleanup work. In my project I am working on, I use theDirector
Class for the cleaning process. Whats happen if I do not that cleaning or if I forget something
to remove or clean…???

Michael [import]uid: 12632 topic_id: 5940 reply_id: 305940[/import]

I don’t know what exactly the Director class does, but there are basically two things to cleanup when finished with them: display objects and event listeners. For display objects you need to manually call removeSelf() to prevent memory leaks, and you need to manually remove event listeners or they will generate errors by trying to call functions that no longer exist. [import]uid: 12108 topic_id: 5940 reply_id: 20463[/import]

How am I supposed to remove my objects?

I use Director Class too, but if I change my levels/scenes, then I get always more and more children.

On the first level I have 4 children, then on the second level (which is an exact copy of level1) I have 12, then on the third already 21 or so…

I can’t remove my objects just so, because it would look stupid if suddenly everything disappears, but it seems, that when I change levels, there is still garbage, although I remove all listeners.

That’s why I think, those childrens are my game objects, which don’t get destroyed by removeSelf().

But how the hell should I remove them? [import]uid: 6587 topic_id: 5940 reply_id: 20484[/import]

A routine like below will cleanup all objects in the group _theContent by first determining the number of objects in _theContent and then removing each one.

[lua]for i=1, _theContent.numChildren do
_theContent:remove(i)
end[/lua]

Adding a transition.to into the above routine will slowly fade each one out

This could easily be turned into a function. [import]uid: 22878 topic_id: 5940 reply_id: 20496[/import]

Hmm, and I was thinking the Director Class will do the job for me, remove all the visibility
objects…???
Another reason why I opened this thread is the question of the necessarity of all this
cleaning jobs… I ask you why we have manually to do this …???
I am confused now… [import]uid: 12632 topic_id: 5940 reply_id: 20578[/import]