How to destroy RL2 in a right way

chiekurs's Avatar

chiekurs

12 May, 2014 07:53 AM

Hey! I have a major problem and I hope I can be helped in here.
So, I have this sub application which is initiated on runtime (all app assets are loaded in separate domain and that works nice) and then destroyed on runtime so another instance, or no instance of app at all, could take its place.
At the start I was hoping that I could go with creating separate container Sprite to host all sub application, create brand new RL2 Context for that app, and then as main container will be removed from stage and all references created on init state removed, it all should just go away... but it doesn't. I was trying to find which of my modules are the ones that stuck but that does not help either as for now there's almost nothing left and still all bunch of RL2 stuff is in memory.
So, what I do for creating my app is this:

containerSpr = new Sprite();
addChild(containerSpr);
context = new Context();
context.install(
    MVCSBundle
    //,Some of my modules which are of no importance
);
context.configure(
    //Configure application data sources
    new ContextView(gameContainer),
    LaunchAppStateManager
);
When it comes to destroy all I do is this:
removeChild(gameContainer);
gameContainer = null;
I tried to run injector.tearDown, I've implemented custom destroy handling (which is initiated by RL2 StageSyncExtension) but that all if of no relevance, I can destroy some parts of my project that way but there's always some major leftovers and now I'm in a stage that most of my leftovers are from RL2, which makes me think that I'm not doing something right.
Any ideas? Ans thanks in advance, I'm getting a bit desperate in here.

UPDATE

Just created a clean RL2 setup to test if anything of my code could be responsible for not releasing application for GC (environment FlashDevelop FP 11.4):

package {
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import robotlegs.bender.bundles.mvcs.MVCSBundle;
    import robotlegs.bender.extensions.contextView.ContextView;
    import robotlegs.bender.framework.impl.Context;
    public class Main extends Sprite {
private var gameContainer:Sprite; private var context:Context; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point stage.addEventListener(KeyboardEvent.KEY_UP, destroy); gameContainer = new Sprite(); addChild(gameContainer); context = new Context(); context.install(MVCSBundle); context.configure(new ContextView(gameContainer)); } private function destroy(e:KeyboardEvent):void { stage.removeEventListener(KeyboardEvent.KEY_UP, destroy); removeChild(gameContainer); gameContainer = null; context = null; } } }
This setup shows 12 megs of consumed memory upon launching; after hitting any key i get trace:
5137 DEBUG Context-0-bc [object StageSyncExtension] Context view has left the stage. Destroying context...
5145 INFO Context-0-bc Context-0-bc Destroying...
5149 DEBUG Context-0-bc [object ViewManagerBasedExistenceWatcher] Removing context existence event listener from container [object Sprite]
5155 DEBUG Context-0-bc [object StageObserverExtension] Destroying genuine StageObserver Singleton
5162 INFO Context-0-bc Context-0-bc Destroy complete
And no reduce of memory...
How can it be?
  1. Support Staff 1 Posted by Shaun Smith on 15 May, 2014 12:33 AM

    Shaun Smith's Avatar
  2. Ondina D.F. closed this discussion on 02 Jul, 2014 07:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac