Results 1 to 5 of 5

Thread: Autowired when components are removed and subsequent addChild is called

  1. #1
    Join Date
    Aug 2009
    Location
    Stuttgart - Germany
    Posts
    2

    Default Autowired when components are removed and subsequent addChild is called

    We use Spring Actionscript to wire ours Views to their Presentation Models. This worked quite fine until we started to remove Components and add them later. This is a problem, because the Presentation Model is prototype scoped and all data in the original presentation model is lost when it is replaced by a new presentation model.

    Is there a possibility to prevent Autowireing at all addChild call when the component is already wired?


    Example:
    SomeUIComponent:
    [Bindable]
    [Autowired]
    public var browserDialogPM:BrowserDialogPM;


    Where the SomeUIComponent is used:
    _content.addChild(someUIComponent);
    --> Autowired ist done the first time in someUIComponent

    _content.removeAllChildren();
    _content.addChild(someUIComponent);
    --> Autowired ist done the second time time in someUIComponent

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default that's a bug/issue indeed

    Hey Andy,

    I had this issue in the back of my mind when autowiring of stage components was implemented, I think I have some ideas on how to tackle this.
    If you can, please add a ticket in JIRA with a feature request for this, I'll try and come up with a solution a.s.a.p.

    You can add bug reports and feature requests if you follow this link:

    http://jira.springframework.org/brow...ACTIONSCRIPTAS

    cheers,

    Roland

  3. #3
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default Fixed in the trunk

    Alright, nevermind the feature request. I have made a small change to the DefaultAutowiringStageProcessor where it now checks if a given component has been autowired yet or not.

    This behavior can optionally be turned off by setting the autowireOnce property to false on the DefaultAutowiringStageProcessor.

    To do this using the configuration, add this XML to your config:

    Code:
    <object class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor" id="defaultAutowiringStageProcessor">
      <property name="autowireOnce" value="false"/>
    </object>
    All these changes can be found in the trunk, do a full checkout here:
    https://src.springframework.org/svn/...cript-as/trunk

    hope that helps,

    cheers,

    Roland

  4. #4
    Join Date
    Aug 2009
    Location
    Stuttgart - Germany
    Posts
    2

    Default

    Hi Roland,

    thanks for your quick response and for fixing the issue.
    I'm new to Actionscript and also to spring actionscript, so i prefer a post to the forum before writing a jira issue.
    As you've already made a fix for this i wont't create a jira isse.

    In fix (revision 677) you use a Dictionary where the object is the reference. If the object is in the Dictionary you skipp subsequent autorwireing.

    For me, this smells bit like a memory leack:
    When the UIComponent object is removed from the stage and all references to it are nulled in client code, I expect the garbage collector to destroy the object. But as there is still a reference to the object from your componentCache. So the garbage collector won't ever delete this component. All stage components that have been autowired will stay in memory forever.

    Maybe i missed something, as i don't speak actionscript fluently right now - i'll be happy if you can tell me why the sollution isn't a memory leak

    The Code snippets i'm referring to:
    protected var componentCacheictionary;
    ...
    override public function process(object:Object):Object {
    if (((componentCache[object] == null) && (_autowireOnce)) || (!_autowireOnce))
    {
    if (_objectFactory && _objectDefinitionResolver) {
    componentCache[object] = true;
    _objectFactory.wire(object, _objectDefinitionResolver.resolveObjectDefinition( object));
    }
    }


    CU
    Andy
    Last edited by AndyBaumann; Aug 28th, 2009 at 02:39 AM.

  5. #5
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default nopes

    Hey Andy,

    the Dictionary I use is created like this: new Dictionary(true).

    Where the true value is for the 'weakKeys' parameter (default its false), which means that the keys in the dictionary (in this case the stage components) are weak references, so the memory leak shouldn't occur.


    cheers,

    Roland
    Last edited by 666shooter; Aug 29th, 2009 at 04:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •