SignalCommand garbage collection

havarez's Avatar

havarez

09 Nov, 2010 03:33 PM

I have CreateLevel command which is mapped as
signalCommandMap.mapSignalClass(CreateLevelSignal, CreateLevelCommand);

It creates a VOLevel object and sends it with - StartLevelSignal
signalCommandMap.mapSignalClass(StartLevelSignal, StartLevelCommand);

In RenderGameMediator i have alistener that does NOTHING

[Inject] public var startLevelSignal :StartLevelSignal;

startLevelSignal.add(startLevel);
private function startLevel( level:VOLevel ):void
{
    //nothing here
}

After startLevel function I need GarbageCollector to clean VOLevel.
But in in SwiftSuspenderInjector I have a strong refference to VOLevel object that keep it from GC.
How to get rif of that refference(see attached pic)

  1. 2 Posted by havarez on 09 Nov, 2010 03:36 PM

    havarez's Avatar

    here is a pic

  2. 3 Posted by ZackPierce on 09 Nov, 2010 07:38 PM

    ZackPierce's Avatar

    Bad news. At this point, the SwiftSuspenders Injector class has no way of directly releasing individual object references.

    Good news. You can, however, use the IInjector#unmap method to remove all mappings for a given class.

    More bad news. The SignalCommandMap uses a child injector of the main injector, so you can't directly call injector.unmap(VOLevel) on the main IInjector instance in your Context.

    Solution: Hack your version of Robotlegs/SignalCommandMap.

    • Make the SignalCommandMap "injector" property public (or perhaps just add a public getter)
    • Call signalCommandMap.injector.unmap(VOLevel) when you're ready to prepare for garbage collection.
  3. 4 Posted by havarez on 10 Nov, 2010 10:45 AM

    havarez's Avatar

    I added getter for Injector property but...
    How to get signalCommandMap instance in my Mediator

    var signalCommandMap:SignalCommandMap = new SignalCommandMap( "what is here?" );
    signalCommandMap.injector.unmap(VOLevel);

    to instantiate SignalCommandMap i need IInjector arg to pass.
    Or should I inject SignalCommandMap?

    Can I create command that will listen for ClearObject signal that has an object(as arg) needs to be unmaped for GC? (what would be the code?)

    Sorry if my questions sound stupid, first time working with DI ... little confused

  4. 5 Posted by havarez on 10 Nov, 2010 11:00 AM

    havarez's Avatar
    [Inject] public var injector:IInjector;
    ...
    var signalCommandMap:SignalCommandMap = new SignalCommandMap(injector);
    signalCommandMap.injector.unmap(VOLevel);

    I get error - Error: Error while removing an injector mapping: No mapping defined for class com.flashracingonline.gloomytruck.model.vo::VOLevel, named ""

  5. 6 Posted by ZackPierce on 10 Nov, 2010 04:21 PM

    ZackPierce's Avatar

    How to get signalCommandMap instance in my Mediator

    You need to inject SignalCommandMap into your mediator, not reinstantiate it. If, like in the previous post, you make a totally new SignalCommandMap out of thin air, it won't have any relevance to your existing mappings. If you use injection, then the injector will provide a reference to your existing SignalCommandMap instance, which should include any mappings you've made at that point.

    [Inject]
    public var signalCommandMap:ISignalCommandMap;

    Can I create command that will listen for ClearObject signal that has an object(as arg) needs to be unmaped for GC?

    Not without some more serious modifications to both Robotlegs and SwiftSuspenders. The the injector.unmap call I'm suggesting is only a work-around that is supposed to operate on whole Class-based mappings, not individual object instances.

    You could, however, make a ClearClassMappingCommand command, but it would really just be very simple wrapper around injector.unmap. You'd also have to go to the hassle of re-mapping that Class if you wanted to inject an instance of it somewhere later.

    public class ClearClassMappingRequested extends Signal
    {
        public function ClearClassMappingRequested()
        {
            super(Class);
        }
    }
    
    
    public class ClearClassMappingCommand
    {
        [Inject]
        public var clazz:Class;
    
        [Inject]
        public var injector:IInjector;
    
        public function execute():void
        {
            injector.unmap(clazz);
        }
    }
  6. 7 Posted by Havarez on 11 Nov, 2010 03:37 PM

    Havarez's Avatar

    Thank yo very much! All works.

  7. Stray closed this discussion on 10 Feb, 2011 06:11 PM.

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