Filed under: AIR, Flex, Resource | Tags: AIR memory problem, image AIR, image issue, memory problem image flex, problem image AIR, problem load image AIR
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.
Enjoy!
8 Comments so far
Leave a comment
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>







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
Comment by Mister August 28, 2008 @ 8:49 pmYes I’m agree with you, I’ll create a sample that it will produce the initial problem.
Meanwhile I suggest to take a look at: http://blog.paranoidferret.com/index.php/2007/12/11/flex-tutorial-an-asynchronous-jpeg-encoder/
Comment by lucamezzalira August 28, 2008 @ 11:07 pmI 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
Comment by seme1 September 3, 2008 @ 12:16 pmThanks 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
Comment by Ashish November 8, 2008 @ 3:06 pmAshish
Re: Ashish. It’s not possible to invoke the garbage directly.
Comment by Robert Reinhard October 27, 2009 @ 8:21 pmWait, nvm, just found this: http://livedocs.adobe.com/flex/3/langref/flash/system/System.html#gc()
Comment by Robert Reinhard October 27, 2009 @ 8:29 pmDear Robert,
Comment by lucamezzalira October 27, 2009 @ 9:18 pmyou 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
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,
Comment by karthikeyan.cs January 17, 2010 @ 7:51 amkarthikeyan.cs