Memory leaks

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory leaks

FlexCoders mailing list
Hi
I created an air application with a schedule.

To populate this schedule with appointment, I launch an httpservice and
result is use to populate an array collection. Each time user change
week, a new request is sending.

The variable myDataCalendar (array collection) is defined as [Bindable]
private var myDataCalendar :ArrayCollection;
I try to reuse the same ArrayCollection, but I think making a mistake
because memory increase each time, and garbage collector seems not working!

  myDataCalendar = new ArrayCollection();
   myDataCalendar.refresh();

So can you help me to understand memory leak.

Best regards
Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks

FlexCoders mailing list
Combine variable declaration and object creation in single statement. See the below pseudo code for example:

private var myDataCalendar :ArrayCollection=new ArrayCollection();

function ChangeWeekHandler(Event){
 myDataCalendar= HttpServiceToGetNextWeekData();
 myDataCalendar.refresh();
}
Note: HttpServiceToGetNextWeekData() should return anonymous objectof type ArrayCollection.

Hope this helps. :-)
Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks

FlexCoders mailing list
To be even more memory conscious, don't instantiate "myDataCalendar" until you have to use it.  Your suggestion indicates you're doing it whenever the object/class instantiates.
 

 function ChangeWeekHandler(Event){
       if(!myDataCalendar) myDataCalendar = new ArrayCollection();
       .
       .
       .
 }
 

 On top of that, make sure you free it up (in the case garbage collection doesn't pick it up).  You can do this by simply setting it to null when you're done with it.
 

 myDataCalendar = null;