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!
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
Yes 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/
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
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
Ashish
Re: Ashish. It’s not possible to invoke the garbage directly.
Wait, nvm, just found this: http://livedocs.adobe.com/flex/3/langref/flash/system/System.html#gc()
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
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,
karthikeyan.cs
Hey, I was searching for a solution and came across your blog. If you are targeting a mac, you could create proxy images with SIPS and then load them in flash (AIR only). I posted a small tutorial on my blog http://www.inklink.co.at/blog/?p=90
hope it helps 🙂