3 Replies Latest reply on May 14, 2010 7:38 AM by ska-man

    Problem with memory allocation of arraycollection by AddItem

    ska-man

      I have a strange problem with the method AddItem.

       

      I made a new item with this code:

      ------

      for (var u:int = 0; u<41; u++){
            pagina=new PageToSave();
            project.addPage(pagina as PageToSave);
      }

      -----

       

      project is an istance of projectblueprint class:

       

      package marcoDoItBetter.utils
      {
          import mx.collections.ArrayCollection;  
          public class ProjectBlueprint
          {
              private var _pages:ArrayCollection;

       

              public function addPage(page:PageToSave):void
              {
                  this._pages.addItem(page);
              }

         }

      }

       

      ----

      PageToSave is a class that extends object.

       

       

       

       

       

      When we create the item using programmatically the addPages method (so using addItem in the _pages arraycollection) we have this result using the expression inspector in the debug mode.

       

      This is on the debugger output:

      pageList = mx.collections.ArrayCollection (@105cf341)   
          [inherited] =    
          [0] = marcoDoItBetter.utils.PageToSave (@113cb461)   
          [1] = marcoDoItBetter.utils.PageToSave (@113cb401)   
          [2] = marcoDoItBetter.utils.PageToSave (@113cb3a1)   
          [3] = marcoDoItBetter.utils.PageToSave (@113cb341)   
          [4] = marcoDoItBetter.utils.PageToSave (@113cb2e1)   
          [5] = marcoDoItBetter.utils.PageToSave (@113cb281)<----------   
          [6] = marcoDoItBetter.utils.PageToSave (@113cb221)   
          [7] = marcoDoItBetter.utils.PageToSave (@113cb1c1)   
          [8] = marcoDoItBetter.utils.PageToSave (@113cb161)   
          [9] = marcoDoItBetter.utils.PageToSave (@113cb101)   
          [10] = marcoDoItBetter.utils.PageToSave (@113cb0a1)   
          [11] = marcoDoItBetter.utils.PageToSave (@113cb041)   
          [12] = marcoDoItBetter.utils.PageToSave (@1140dfa1)   
          [13] = marcoDoItBetter.utils.PageToSave (@1140df41)   
          [14] = marcoDoItBetter.utils.PageToSave (@1140dee1)   
          [15] = marcoDoItBetter.utils.PageToSave (@1140de81)   
          [16] = marcoDoItBetter.utils.PageToSave (@1140de21)   
          [17] = marcoDoItBetter.utils.PageToSave (@1140ddc1)   
          [18] = marcoDoItBetter.utils.PageToSave (@1140dd61)   
          [19] = marcoDoItBetter.utils.PageToSave (@1140dd01)   
          [20] = marcoDoItBetter.utils.PageToSave (@1140dca1)   
          [21] = marcoDoItBetter.utils.PageToSave (@1140dc41)   
          [22] = marcoDoItBetter.utils.PageToSave (@113cb281)<------------   
          [23] = marcoDoItBetter.utils.PageToSave (@1140db81)   
          [24] = marcoDoItBetter.utils.PageToSave (@1140db21)   
          [25] = marcoDoItBetter.utils.PageToSave (@1140dac1)   
          [26] = marcoDoItBetter.utils.PageToSave (@1140da61)   
          [27] = marcoDoItBetter.utils.PageToSave (@1140da01)   
          [28] = marcoDoItBetter.utils.PageToSave (@1140d9a1)   
          [29] = marcoDoItBetter.utils.PageToSave (@1140d941)   
          [30] = marcoDoItBetter.utils.PageToSave (@1140d8e1)   
          [31] = marcoDoItBetter.utils.PageToSave (@1140d881)   
          [32] = marcoDoItBetter.utils.PageToSave (@1140d821)   
          [33] = marcoDoItBetter.utils.PageToSave (@1140d7c1)   
          [34] = marcoDoItBetter.utils.PageToSave (@1140d761)   
          [35] = marcoDoItBetter.utils.PageToSave (@1140d701)   
          [36] = marcoDoItBetter.utils.PageToSave (@1140d6a1)   
          [37] = marcoDoItBetter.utils.PageToSave (@1140d641)   
          [38] = marcoDoItBetter.utils.PageToSave (@1140d221)   
          [39] = marcoDoItBetter.utils.PageToSave (@1140d5e1)   
          [40] = marcoDoItBetter.utils.PageToSave (@1140d461)   
          source = Array (@1140c9a9)  

       

       

      as you can see the [5] and the [22] PageToSave instances of the class has the same address referencing(or internal flex id.

      I don't know the exact name of it). It occurs in a totally random manner.

      sometimes all goes well, sometimes there are more than one duplicate with random address referencing match.

       

       

      I don't want duplicate instances but I want independent instances.

       

       

      I tried changing addItem with

           this._pages.addItemAt(page,0);

       

      Same result.

       

      I also tried pagina=null before the new statement but same result

      ------

      for (var u:int = 0; u<41; u++){
             pagina=new PageToSave();
             project.addPage(pagina as PageToSave);

            pagina = null;
      }

      -----

       

      is a garbage collector issues?

      how we can fix it?

       

       

       

      Thank you