[ 
https://issues.apache.org/jira/browse/FLEX-27837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13774283#comment-13774283
 ] 

Alex Harui commented on FLEX-27837:
-----------------------------------

IMO, the code is correct.  Please provide a test case that indicates 
differently.  It is true that the documentation should be different: the 
weakReference parameter determines if the reference from the host to the 
ChangeWatcher is strong or weak, so there's an "essyfix" to change the 
documentation.

But AFAICT, the code is correct.  The weakReference parameter is not passed 
into the ChangeWatcher constructor, but is assigned to the instance after 
construction and before reset() is called where it appears to be properly 
applied.

The reason a chain of ChangeWatchers are not available for GC is that the 
'next' property of the ChangeWatcher forms a hard reference chain of 
ChangeWatchers.  The point of the weakReference parameter is to make sure the 
ChangeWatchers aren't pinned in memory by the host and other objects in the 
chain, but as long as you have a strong reference to a ChangeWatcher all of 
remainder of that chain appears to be pinned in memory as well, just not by the 
host and other objects.
                
> ChangeWatcher bug
> -----------------
>
>                 Key: FLEX-27837
>                 URL: https://issues.apache.org/jira/browse/FLEX-27837
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: .Unspecified - Framework
>    Affects Versions: Adobe Flex SDK Previous
>         Environment: Affected OS(s): Windows
> Affected OS(s): Windows XP
> Language Found: English
>            Reporter: Adobe JIRA
>              Labels: easyfix
>
> When I used this class BindingUtils to binding work, I called this method:
> public static function bindSetter(setter:Function, host:Object,
>                                       chain:Object,
>                                       commitOnly:Boolean = false,
>                                       useWeakReference:Boolean = 
> false):ChangeWatcher
> I found there is a wrong description about the "useWeakReference", below is 
> the signature of useWeakReference in the API Document:
>       useWeakReference : Boolean
> (default = false) Determines whether the reference to the host is strong or 
> weak.
> but I don't think it determines the host, but the ChangeWatcher instance 
> itself, it determines whether the reference to the ChangeWatcher instance is 
> strong or weak.
> So,I test the ChangeWatcher instance is real be gced. If the chain's length 
> is only 1,the useWeakReference works, the ChangeWatcher instance will be 
> gced,but if the chain's length is more than 1,the useWeakReference doesn't 
> work.
> the source code:
> BindingUtils :
> public static function bindSetter(setter:Function, host:Object,
>                                       chain:Object,
>                                       commitOnly:Boolean = false,
>                                       useWeakReference:Boolean = 
> false):ChangeWatcher
>     {
>         var w:ChangeWatcher =
>             ChangeWatcher.watch(host, chain, null, commitOnly, 
> useWeakReference);
>         
>         if (w != null)
>         {
>             var invoke:Function = function(event:*):void
>             {
>                 setter(w.getValue());
>             };
>             w.setHandler(invoke);
>             invoke(null);
>         }
>         
>         return w;
>     }
> ChangeWatcher :
> public static function watch(host:Object, chain:Object,
>                                  handler:Function,
>                                  commitOnly:Boolean = false,
>                                  useWeakReference:Boolean = 
> false):ChangeWatcher
>     {
>         if (!(chain is Array))
>             chain = [ chain ];
>         if (chain.length > 0)
>         {
>             var w:ChangeWatcher =
>                 new ChangeWatcher(chain[0], handler, commitOnly,
>                     watch(null, chain.slice(1), handler, commitOnly));     
> //there is the reason!the default arg is false,so the 1st ChangeWatcher is 
> "useWeakReference = true",but others are "ChangeWatcher = false" 
>             w.useWeakReference = useWeakReference;
>             w.reset(host);
>             return w;
>         }
>         else
>         {
>             return null;
>         }
>     }
> I think the right code must be "watch(null, chain.slice(1), handler, 
> commitOnly, useWeakReference));  "
> the chain of ChangeWatchers will not be gced.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to