quick trick:
http://blogs.eyepartner.com/adrian/flex/flex-tip-6-garbage-collection-in-flex/



On Thu, Jan 29, 2009 at 6:41 AM, Sander Schuurman <
sander.schuur...@oswaldandruby.com> wrote:

> Thnx! ran a few tests on a server; and indeed my code is doing great, and
> the GC occurs when some more memory is needed... thnx again...
>
> I think the concept of this GC is key in AS3 development
>
> -----Original Message-----
> From: flashcoders-boun...@chattyfig.figleaf.com [mailto:
> flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Nate Beck
> Sent: Wednesday, 28 January 2009 17:34
> To: Flash Coders List
> Subject: Re: [Flashcoders] Garbage Collection difficulty
>
> Ah yes... I knew I read it somewhere... It's in that Grant Skinner article.
>
>
> *Deferred GC and Indeterminacy*
> A *very* important thing to understand about the Garbage Collector in FP9
> is
> that it's operations are deferred. Your objects will not be removed
> immediately when all active references are deleted, instead they will be
> removed at some indeterminate time in the future (from a developer
> standpoint). The GC uses a set of heuristics that look at RAM allocation
> and
> the size of the memory stack (among other things) to determine when to run.
> As a developer, you must accept that fact that you will have no way of
> knowing when (or even if) your inactive objects will get deallocated. You
> must also be aware that inactive objects will continue to execute
> indefinitely (until the GC deallocates it), so code will keep running (ex.
> enterFrames), sounds will keep playing, loads will keep happening, events
> will keep firing, etc.
>
> It's very important to remember that you have no control over when your
> objects will be deallocated, so you must make them as inert as possible
> when
> you are finished with them. Strategies to manage this will be the focus for
> a future article.
>
>
> On Wed, Jan 28, 2009 at 8:31 AM, Nate Beck <n...@tldstudio.com> wrote:
>
> > It was my understanding that Garbage Collection doesn't always occur
> right
> > away.  When you have orphaned objects sitting on the heap, they are *
> > eligible* for garbage collection.  That doesn't mean they will be removed
> > from memory right away.  Especially if you're testing for JUST that to
> > happen.  Usually GC occurs when more memory is needed.
> >
> > Someone else could probably speak to this topic much more intelligently
> > than me.. but that was my understanding of how GC in general works.
> >
> > Cheers
> >
> >   On Tue, Jan 27, 2009 at 6:04 AM, Sander Schuurman <
> > sander.schuur...@oswaldandruby.com> wrote:
> >
> >> Thnx for the links... tried some, but still with no success... I now
> have
> >> the following:
> >>
> >> public class Image extends MovieClip
> >> {
> >>  private var _thumbLoader:Loader;
> >>  private var _largeLoader:Loader;
> >>
> >>  private var _thumb:Bitmap;
> >>  private var _large:Bitmap;
> >>
> >>  public function loadThumb() :void
> >>  {
> >>  _thumbLoader = new Loader();
> >>  _thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> >>                                        thumbLoaded, false, 0, true);
> >>  _thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> >>                                        errorOccured, false, 0, true);
> >>  _thumbLoader.load(new URLRequest(_tu));
> >>  }
> >>
> >>  private function thumbLoaded( e :Event ) :void
> >>  {
> >>  _thumb = Bitmap(e.currentTarget.content);
> >>  _thumb.smoothing = true;
> >>
> >>  addChild(_thumb);
> >>
> >>  _thumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,
> >>
> >>  thumbLoaded);
> >>
>  _thumbLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,
> >>
> >>  errorOccured);
> >>  _thumbLoader = null;
> >>
> >>  dispatchEvent(new Event(Image.IMG_LOADED));
> >>  }
> >>
> >>  public function loadLarge() :void
> >>  {
> >>  _largeLoader = new Loader();
> >>  _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> >>                                        largeLoaded, false, 0, true);
> >>  _largeLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> >>                                        errorOccured, false, 0, true);
> >>  _largeLoader.load(new URLRequest(_lu));
> >>  }
> >>
> >>  private function largeLoaded( e :Event ) :void
> >>  {
> >>  _large = e.currentTarget.content;
> >>  _large.smoothing = true;
> >>  addChild(_large);
> >>
> >>  _largeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,
> >>
> >>  largeLoaded);
> >>
>  _largeLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,
> >>
> >>  errorOccured);
> >>  //_largeLoader.content.dispose();
> >>  _largeLoader = null;
> >>
> >>  dispatchEvent(new Event(Image.IMG_LOADED));
> >>  }
> >>  public function disposeLarge() :void
> >>  {
> >>  if (_large)
> >>   {
> >>    removeChild(_large);
> >>    _large.bitmapData.dispose();
> >>    _large = null;
> >>   }
> >>  }
> >>
> >> public function dispose() :void
> >>  {
> >>  disposeLarge();
> >>
> >>  removeChild(_thumb);
> >>  _thumb.bitmapData.dispose();
> >>  _thumb = null
> >>  }
> >>
> >> }
> >>
> >> Anyone some tips? The large bitmap stays in memory...
> >>
> >> -----Original Message-----
> >> From: flashcoders-boun...@chattyfig.figleaf.com [mailto:
> >> flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike
> >>  Sent: Wednesday, 21 January 2009 21:18
> >> To: Flash Coders List
> >> Subject: Re: [Flashcoders] Garbage Collection difficulty
> >>
> >> Hi,
> >>
> >>    I think if you use it locally, you still have to "dispose" of it:
> >>
> >>    http://www.bartclaessens.com/tag/memory-management/
> >>
> >>
> >> http://labs.bigspaceship.com/2007/02/28/flash-performance-tips-part-ii/
> >>
> >>    http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html
> >>
> >>    Search for "dispose" in some of these - also, one of the comments in
> >> Grant's article mentions testing in the IDE vs testing in the browser
> >> gives different results for loaded images.
> >>
> >>    HTH
> >>
> >>    Glen
> >>
> >> Sander Schuurman wrote:
> >> > That's a local variable right? Doesn't it happen automatic?
> >> > I must concentrate on the _large Sprite, isn't it?
> >> >
> >> >
> >> > -----Original Message-----
> >> > From: flashcoders-boun...@chattyfig.figleaf.com [mailto:
> >> flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike
> >> > Sent: Wednesday, 21 January 2009 12:20
> >> > To: Flash Coders List
> >> > Subject: Re: [Flashcoders] Garbage Collection difficulty
> >> >
> >> > Hi,
> >> >
> >> >     Do you have to destroy the Bitmap you create in the largeLoaded
> >> > function???
> >> >
> >> >     Glen
> >> >
> >> > Sander Schuurman wrote:
> >> >
> >> >> Hi cool list,
> >> >>
> >> >> I'm struggling with my Image class. It's supposed to load and unload
> >> different sized images dynamicly; but I can't seem to get it to work
> >> properly. The loading works fine, but the unloading not for the full
> 100%.
> >> It visually unloads the image, but it remains in the memory. I have
> tried
> >> several different things; I'm a bit stuck now.
> >> >>
> >> >> Here is a stripped class:
> >> >>
> >> >> public class Image extends MovieClip
> >> >> {
> >> >> ...
> >> >>             private var _largeLoader:Loader;
> >> >> private var _large:Sprite;
> >> >> ...
> >> >> public function Image(     thumbUrl           :String,
> >> >>                                                 normalUrl
> >>  :String,
> >> >>                                                 largeUrl :String   )
> >> >> {
> >> >>                         _tu = thumbUrl;
> >> >>                         _nu = normalUrl;
> >> >>                         _lu = largeUrl;
> >> >> }
> >> >> ...
> >> >> public function loadLarge() :void
> >> >> {
> >> >>                         _largeLoader = new Loader();
> >> >>
> >> _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> largeLoaded,
> >> false, 0, true);
> >> >>
> >> _largeLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> >> errorOccured, false, 0, true);
> >> >>                         _largeLoader.load(new URLRequest(_lu));
> >> >> }
> >> >>
> >> >> private function largeLoaded( e :Event ) :void
> >> >> {
> >> >>                         var b:Bitmap = Bitmap(largeLoader.content);
> >> >>
> >> >>
> >> _largeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,
> >> largeLoaded);
> >> >>
> >>
> _largeLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,
> >> errorOccured);
> >> >>                         _largeLoader = null;
> >> >>
> >> >>                         _large = new Sprite();
> >> >>                         _large.addChild(b);
> >> >>                         addChild(_large);
> >> >>
> >> >>                         dispatchEvent(new Event(Image.IMG_LOADED));
> >> >> }
> >> >> ...
> >> >>             public function clear( full :Boolean = false ) :void
> >> >>             {
> >> >>                         // clear normal img and large img
> >> >>                         ... ?
> >> >>
> >> >>                         // tried things like:
> >> >>
> >> >>                         //_normal.removeChildAt(0);
> >> >>                         //_normal = null;
> >> >>                         //removeChild(_normal);
> >> >>                         //_large.removeChildAt(0);
> >> >>                         //_large             = null;
> >> >>                         //removeChild(_large);
> >> >>                         //delete(_normal.removeChildAt(0));
> >> >>                         //delete(_large.removeChildAt(0));
> >> >>
> >> >>                         // removes the images visually, but they
> won't
> >> get GC'ed
> >> >>
> >> >> if (full)
> >> >> {
> >> >>             // clear thumb and itself
> >> >> }
> >> >>             }
> >> >> }
> >> >>
> >> >> Thanks in advance!
> >> >> _______________________________________________
> >> >> Flashcoders mailing list
> >> >> Flashcoders@chattyfig.figleaf.com
> >> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >> >>
> >> >>
> >> >>
> >> >>
> >> >
> >> > _______________________________________________
> >> > Flashcoders mailing list
> >> > Flashcoders@chattyfig.figleaf.com
> >> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >> >
> >> > _______________________________________________
> >> > Flashcoders mailing list
> >> > Flashcoders@chattyfig.figleaf.com
> >> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >> >
> >> >
> >> >
> >>
> >> --
> >>
> >> Glen Pike
> >> 01326 218440
> >> www.glenpike.co.uk <http://www.glenpike.co.uk>
> >>
> >> _______________________________________________
> >> Flashcoders mailing list
> >> Flashcoders@chattyfig.figleaf.com
> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >>
> >> _______________________________________________
> >> Flashcoders mailing list
> >> Flashcoders@chattyfig.figleaf.com
> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >>
> >
> >
> >
> > --
> >
> > Cheers,
> > Nate
> > ----------------------------------------
> > http://blog.natebeck.net
> >
> >
> >
>
>
> --
>
> Cheers,
> Nate
> ----------------------------------------
> http://blog.natebeck.net
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to