[
https://issues.apache.org/jira/browse/FLEX-27837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13774385#comment-13774385
]
nigel magnay commented on FLEX-27837:
-------------------------------------
>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.
>
That is true for the first change watcher in the chain, but NOT for the
subsequent ones. It has nothing to do with the next reference, it's the
reference back to 'handler' that's at issue.
The line here:
var w:ChangeWatcher =
new ChangeWatcher(chain[0], handler, commitOnly,
watch(null, chain.slice(1), handler, commitOnly));
Is a recursive call. The parameter for the recursive call is being defaulted,
so it's equivalent to
var w:ChangeWatcher =
new ChangeWatcher(chain[0], handler, commitOnly,
watch(null, chain.slice(1), handler, commitOnly, >>> false
<<< ));
So if we call with something like
ChangeWatcher.watch(thing, ["a","b","c"], handler, false, true);
Trying to follow the API, which states:
@param useWeakReference (default = false) Determines whether
the reference to <code>handler</code> is strong or weak. A strong
reference (the default) prevents <code>handler</code> from being
garbage-collected. A weak reference does not.
Then this is easily demonstrated to not be true. The ChangeWatcher created for
monitoring 'b's value of 'c' has a useWeakReference value set to FALSE in the
recursive call.
> 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