Working with big images and AIR (memory issue: SOLVED!)

A couple of weeks ago I solved a big problem in an AIR application that I’m working on.
This application is an images manipulator; the most important problem when you work on a desktop application is that a user could be uses any kind of images, from 200kb to 5mb!

This problem is not easy to solve when you work with a lots of images because memory use increase a lots.

First of all I tried to use a “normal” load of an images working with Flex Image component, but every time that I load an 3MB image from a folder in my desktop, allocated memory grows up a lot! I arrive to use, with 10 images of the same dimension (3MB each one), 750MB of memory allocated for my application… that’s crazy!!! 
If you want create a batch you have so many problem to preview images and working with them.

So I find a good solution to use less memory (30 – 40MB for all AIR application) working with BitmapData class and Loader class.
I create a zip file where you can find a sample with a couple of images, download it to take a look. 

In this sample you can find 2 buttons, the first one load an image with Image component the other one load image with a class that I made to solve this problem.
When you try it, please open Task Manager (on Windows: right click in system bar) or Activity Monitor (on Mac: Applications>Utilities) and take a look at process and memory that every method use to do the same thing.

If you have any comment, suggestion or so on, please feel free to add a comment at this post or contact me directly.


Published by


I’m the VP of Architecture at DAZN with more than 15 years of experience, a Google Developer Expert on Web Technologies and the London Javascript community Manager I had the chance to work on cutting-edge projects for mobile, desktop, web, TVs, set top boxes and embedded devices. I am currently managing DAZN, a sports video platform based on the cloud with millions of users that are watching live and on-demand contents. I'm the author of Front-End Reactive Architectures published by APress: I think the best way to use any programming language is mastering their models, that’s why I spent a lot of time studying and researching on topics like OOP, Functional and Reactive programming. In my spare time, I wrote for national and international technical magazines and editors, I'm also a technical reviewer for APress, Packt Publishing, Pragmatic Bookshelf and O'Reilly. I was speaker at: O'Reilly media webinars, O'Reilly Software Architecture (San Francisco & London), O'Reilly Fluent (San Jose), O'Reilly Oscon (London), Google Developers Summit (Krakow), Google DevFest (London), Frontend Devs Love (Amsterdam), Voxxed Days (Belgrad & Bristol), JeffConf (Milan), International Javascript Conference (Munich & London), JS Poland (Warsaw), Code Europe (Wroclaw), JSDay (Verona), CybercomDev (Łódź), Jazoon Conference (Bern), JDays (Göteborg), Codemotion (Milan), FullStack Conference (London), React London UG (London), Scrum Gathering (Prague), Agile Cymru (Cardiff), Scotch on the rocks (Edinburgh & London), 360Max (San Francisco), PyCon (Florence), Lean Kanban Conference (London), Adobe Creative Suite CS 5.5 - Launch event (Milan), Mobile World Congress (Barcelona)

9 thoughts on “Working with big images and AIR (memory issue: SOLVED!)”

  1. I downloaded your AIR application and code sample. The tests I did on my Mac did not show any significant difference in memory or process for either image loading. Maybe you need to create an example that shows the initial problem, loading multiple images into the application uses excessive memory.

    I have a similar issue when I upload ByteArray data using FileStream in AIR. The entire bytes of a file are first read into AIR, then posted to a web site. Loading the entire bytes of the file increases the application memory significantly. I don’t think using ByteArray or BitMap saves any CPU memory or processing.

    – Mister

  2. I am having memory problems with the JPEGAsyncEncoder you mentioned. When loading many images, it consumes too much memory. Have you tried your class with JPEGAsyncEncoder ? or rather ,, can is there a way to use it with JPEGAsyncEncoder ?

    Thank you in advance for your help

  3. Thanks for your valuable code.
    Could you tell me how can I invoke Garbage Collector in Flash Palyer. Since I am making an Explorer kind of thing in AIR and when i select a folder contents with thumbnail view i take almost 500 MB. any work around on that

    Thanks in Advance

      1. Dear Robert,
        you can use gc() only when you are testing your app not in a final release version.
        So if you want to force GC you must work with FP 10 and UnloadAndStop method of Loader object and you can solve this problem

  4. hi… i am also facing the same issue with my application. i tried to download your files, but the link you given is take me to some other sites. could you please let me know the link..

    Thanks in advance,

Leave a Reply to Ashish Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s