# Loader eats up memory

**URL:** <https://forum.kirupa.com/t/loader-eats-up-memory/311520>\
**Category:** Uncategorized\
**Created:** [July 8, 2010, 9:03pm UTC](https://forum.kirupa.com/t/loader-eats-up-memory/311520 "2010-07-08T21:03:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tempo](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@tempo](https://forum.kirupa.com/u/tempo)\
**Post date:** [July 8, 2010, 9:03pm UTC](https://forum.kirupa.com/t/loader-eats-up-memory/311520/1 "2010-07-08T21:03:14Z")

</div>

I wrote the following code to check memory when loading a big image (~20Mb)

Every time I do mouse click, the application eats up memory, so something doesn’t get deleted or cleaned with GC but I can’t figure out what exactly.

Can anyone please tell me how to fix it? Thanks!

imageLoader.as

```php

package {

    import flash.display.Loader;
    import flash.net.URLRequest;

    public class imageLoader {

        var fname:String;
        var loader:Loader;

        public function imageLoader(fname:String) {
            this.fname = fname;
        }

        function init() {
            loader = new Loader();
            var request:URLRequest = new URLRequest(fname);
            loader.load(request);
        }

    }

}

```

test.as

```php

package {

    import flash.display.MovieClip;
    import flash.display.Graphics;
    import flash.events.MouseEvent;

    import imageLoader;

    public class test extends MovieClip {

        var mapImg:imageLoader;

        public function test() {

            var mc:MovieClip = new MovieClip();
            mc.graphics.beginFill(0xff0000, 1);
            mc.graphics.drawCircle(0,0,100);
            mc.graphics.endFill();
            addChild(mc);

            buttonMode = true;
            addEventListener(MouseEvent.CLICK, mouseClick);

        }

        private function mouseClick(e:MouseEvent) {
            if (mapImg != null) {
                Bitmap(mapImg.loader.content).bitmapData.dispose();
                mapImg.loader.unload();
                mapImg.loader = null;
                mapImg = null;
            }
            mapImg = new imageLoader("image.png");
            mapImg.init();
        }

    }

}

```
