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.


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

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