Im going rage and mad with this damn thing. When i change scene in scene manager, the previous scene keeps running, WHY AND WHAT A HELL, im doing remove events from previous scene, im doung removing events from world in previous scene, im doing killing objects with events from previous level, AND THIS HELL STILL NOT ENOUGHT, how was this stupid born ? And how to fix this, i hear sounds from previous levels, therefore i sould find and stop all sounds, level management makes me crazy !
vk.com/yan_alex
Comments
http://giderosmobile.com/forum/discussion/480/gideros-game-template/p1
It looks like you are not very familiar with GC managed engines, like lua, I suggest your read a little more about it and things will become clearer (hopefully).
Main point is with GC managed objects, you just can't destroy something, it gets destroyed when system discovers that it is no longer used. By "no longer used", I mean that no part of the code (and Gideros) hold a reference to it. You can force a discovery of those stale objects by issuing a 'collect garbage' procedure, but first make sure that no reference still exists to the object your want to destroy.
You have to watch out for 'hidden' references, for example Sprites used by a MovieClip or event listeners: if you attach a listener to some other object, then that object will hold a reference to the listener (in order to call it later).
Someone in the forum posted 'leaky.lua', which may be of some help.
Say me why Garbage Collector doesnt fires up when i do remove world from level and make it as NIL. Seems should work, yeah ? But damn NO, it doesnt mean for engine nothing ... still wondering what a hell inside of lua ..
http://giderosmobile.com/forum/discussion/comment/9441#Comment_9441
Since Gidero does support OOP approach, I don't see any problems managing your own references in your own class, like Enemy class. Create a destroy function removing anything you want to remove and call it on scene end.
But as I said, you are probably hitting some specific case, cause for me most of it works out of the box, and I don't need to remove anything specifically, if I maintain the correct hierarchy of items
There is only one specific case found by the @bowerandy that when you add event listener to global object, but pass data as some local object, the local object will not be garbage collected until the global object is not collected.
Here is more information on this topic: http://www.giderosmobile.com/forum/discussion/2818/a-warning-about-memory-management-complacency#Item_1
You could possibly have other global classes for managers that you have duplicated throughout other scenes too.
There should not be any problem with sprites and events (apart from mentioned single situation). If you have some problem regarding events, please try to find small simple example and provide it here.
if you have some longer sounds, then yes, they will still play even if the scene have changed, because sounds are not tied, nor bound to the scene.
So in that case as @antix have mentioned, global Sound object would be best solution, as you would be able to stop all the sounds.
You can check out my Game template as an example:
https://github.com/ar2rsawseen/GameTemplate
And same goes for timers. They are not bound to scene, they don't know that scene ended.
So there are some events for the scenes, so you would know when scene started and ended, and you could execute some code, like stop all timers:
http://docs.giderosmobile.com/reference/gideros/Timer/stopAll#Timer.stopAll
The idea is to have each object self contained. Have a class like Enemy, and it manages all its Timers internally (or scene manages timers for group of enemies, etc) so you would know all times and stop them, etc.
I understand how frustrated you must feel, spending so much time on the project and learning about such quirks only know, but unfortunately I don't think there is more to do, then reorganize your code in a way it would work properly.
We can start with some specific situations which are not working for you, you can post them on the forum and we all would gladly discuss them and help you out
Likes: antix
Don't give up though. Redesign it and make it better in the next iteration!
Reason - Enemy has timer for starting patroling area, when he didnt see player.
Solved - Timer.stopAll() on scene exitBegin, unfortunately Timer events didnt removed after sprite been removed !!!
Likes: hgy29
and stop/remove all Sprite related timers there
yet i guess it's not hard to do this for yourself just by redefining the addeventlistener method and adding there a line that puts these informations in some table of that sprite.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
If you have some soundStream with COMPLETE event listener IT WOULD NOT BEEN collecet also !!!
I resolve this by this way - add EVENT listener, if not SoundChannel:isPlaying() do action
Likes: antix