2 Replies Latest reply on Jul 20, 2010 5:39 AM by NewFlo

    Change Watcher and Memory leaks...

    NewFlo

      Hello, everybody!

      I am currently working on a medium application using a tilelist with a custom itemrenderer.

      The itemrenderer uses the static methodes of the ChangeWatcher-Class to get change notifications

      on some of the properties on its value-Object. The ChangeWatchers are added every time the set data methode

      is used. I felt to do so, because the data object may change if some data-filters are applied. I am no exp. that

      the memory usage is increasing if i redownload the data. I guess maybe my use of ChangeWatcher - Class

      is inproperly, but i haven't found a possability to remove the ChangeWatchers as it works with eventlisteners.

      Can anybody provide some sugesstions on this topic? Following the set data methode of the itemrenderer.

       

      Thx in advance! Florian

       

      Set data:

      override public function set data(workItem:Object):void
      {
          _workItem = workItem as WorkItemVO;
          //data = workItem;
          selectionStatusChanged = true;

       

          ChangeWatcher.watch(_workItem, ['selected'], workitem_changeHandler);
          ChangeWatcher.watch(_workItem, ['progress'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['hasAttachments'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['hasComments'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['hasFeedback'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['workItemType'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['data'], workitem_workItemDataChangedHandler);
          ChangeWatcher.watch(_workItem, ['hasNoHQFeedback'], workitem_workItemDataChangedHandler);
          workItemDataChanged = true;
          setWorkItemTooltip();
          setDataFromWorkItem();
          this.invalidateProperties();
          this.invalidateDisplayList();
      }

        • 1. Re: Change Watcher and Memory leaks...
          rootsounds Level 4

          Your theory makes sense since you are applying new ChangeWatchers without removing the old ones. You will need to maintain references to each ChangeWatcher that you create. With these, you can use ChangeWatcher.reset(newHost:Object) to assign a new host for it to watch in place of the old one. This way you don't have any old ChangeWatchers hanging around. Instead, you just keep reusing the same set.

          • 2. Re: Change Watcher and Memory leaks...
            NewFlo Level 1

            According to your suggestion i added a vector filled with the changeWatchers returned by the watch-Methode (are created at the first call of the setData-Methode). If another call to this methode appears and the changewatchers are already created, i iterate over the vector and use the reset()-Methode.

            This seems to work! Thx!

             

            Following the set data-Methode including the changes i made:

            protected var changeWatchers:Vector.<ChangeWatcher> = new Vector.<ChangeWatcher>();

             

            override public function set data(workItem:Object):void
            {
                _workItem = workItem as WorkItemVO;
                //data = workItem;
                selectionStatusChanged = true;
               
                //if renderer is created the first time, the changeWatchers for the icon properties are created.
                //After the creation of the change-Watchers
                if(!dataWasSetAndChangeWatchersAreInitialized)
                {
                    dataWasSetAndChangeWatchersAreInitialized = true;
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['selected'], workitem_changeHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['progress'], workitem_workItemDataChangedHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['hasAttachments'], workitem_workItemDataChangedHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['hasComments'], workitem_workItemDataChangedHandler));   
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['hasFeedback'], workitem_workItemDataChangedHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['workItemType'], workitem_workItemDataChangedHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['data'], workitem_workItemDataChangedHandler));
                    changeWatchers.push(ChangeWatcher.watch(_workItem, ['hasNoHQFeedback'], workitem_workItemDataChangedHandler));

             

                }
                else
                {
                    //Set new host-Object for already created change-Watchers
                    for(var i:Number = 0; i < changeWatchers.length; i++)
                    {
                        changeWatchers[i].reset(_workItem);
                    }
                }
               
                workItemDataChanged = true;
                setWorkItemTooltip();
                setDataFromWorkItem();
                this.invalidateProperties();
                this.invalidateDisplayList();
            }