# Pathologic obsession of "Optimal" as3 (?)

**URL:** <https://forum.kirupa.com/t/pathologic-obsession-of-optimal-as3/275352>\
**Category:** Uncategorized\
**Created:** [November 12, 2008, 8:34pm UTC](https://forum.kirupa.com/t/pathologic-obsession-of-optimal-as3/275352 "2008-11-12T20:34:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Didi32](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Didi32](https://forum.kirupa.com/u/Didi32)\
**Post date:** [November 12, 2008, 8:34pm UTC](https://forum.kirupa.com/t/pathologic-obsession-of-optimal-as3/275352/1 "2008-11-12T20:34:08Z")

</div>

Hi, I’m not a pro actionscripter but often asked to show some of my code to potential employers to prove that I’m not a total lunatic. I came to wonder whether my code is optimal or not and if it could be improved to be more efficient.  
First, is there a book a website or something else that talks about optimizing your code (garbage collection, memory etc…)?

My second question goes with a concrete example of what I wonder about, here is an instance of the Loader class that I am creating in a custom class like this for an image gallery:

```auto
public class CustomClass extends Sprite {
        public var loader:Loader;
        
        
        public function CustomClass(url:String) {
            init(url);
        }
        
        private function init(url:String):void {
            
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
            var urlRequest:URLRequest = new URLRequest(url);
            loader.load(urlRequest);
            
        }
        
        private function initListener(e:Event):void {
            var loaderData:BitmapData = Bitmap(loader.content).bitmapData;
            var b:Bitmap = new Bitmap(loaderData);
            b.smoothing = true;
            addChild(b);
            trace("bitmap smoothing of " + loader.contentLoaderInfo+ " is " + b.smoothing);

            
        }
        
    }

```

After creating a new instance of this CustomClass, I directly access the loader as loader.load() to change the picture after some events are triggered. The event listener (initListener) is however triggered every time I use the loader.load() and adds a child bitmap again and again. So what I came to wonder is whether I’ve got a huge pile of images under each other without doing anything for them to be removed. Is there a way to replace the previous instance of b rather than add one every time or does it make no difference at all because Flash takes care of getting rid of it.

Thanks,
