flex-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "nigel magnay (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLEX-27837) ChangeWatcher bug
Date Mon, 23 Sep 2013 10:30:03 GMT

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

nigel magnay commented on FLEX-27837:
-------------------------------------

Please find attached demo project;

If you click Test1, which registers for events in a model '1 layer deep', you can see that
change events fire when you click 'Change B' but not 'Change C'. This is as you would expect.

When you click 'release', then click either change button - no events are received, so the
count does not go up. This is as you would expect, because we asked for a weakly referenced
changewatcher.

If you click Test2, which registers for events in a model '2 layer deep', you can see that
change events fire when you click 'Change B' and 'Change C'. This is as you would expect.

When you click 'release', then click either change button - events are still received. This
is because the secondary change watcher in the chain incorrectly has a strong reference to
the change handler.


Test 3 and 4 are the same as 1 or 2, but with a 'fixed' ChangeWatcher.watch implementation,
as described. In this instance releasing the objects allows the weak change watchers to also
release, and events fired after 'release' is clicked correctly do not get sunk.

                
> 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
>         Attachments: BrokenFlex.zip
>
>
> 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

Mime
View raw message