Load / unload numerous images in air application (memory leak?)
Hi,
after struggling for a few days with this, I realized I need help!
I am trying to make an application load and display A LOT (hundreds) of images thumbnails at various position in a big area. The problem is that when I try to unload and reload images, I end up with an increasing memory, that does not get collected by the garbage collector.
My first challenge was to load images from anywhere in the computer (I am quite new to flex), which I solved by using a File reference and a Loader using the url extracted from the file:
private function createImage():void {
var img_:String = "1905_a_mondrian.jpg";
var imageFile:File = new File();
imageFile.nativePath = imagesPath + "/" + img_;
var imageLoader:Loader = new Loader();
// useWeakReference permits the GC to collect the memory when the eventListener is dropped
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded, false, 0, true);
imageLoader.load(new URLRequest(imageFile.url));
imageFile = null;
I make sure I remove the eventListener in the loaded method:
e.target.content.removeEventListener(Event.COMPLETE, loaded);
And then Populate an external component:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
x="-100" y="-100" width="200" height="200" >
<!-- The trick is right above this line: offset the anchor point to center the component around -->
<fx:Script>
<![CDATA[
import mx.controls.Image;
[Bindable]
public var image:Image;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Image id="img_" source="{image}" horizontalCenter="0" verticalCenter="0" autoLoad="true" />
<!-- impair width and height results in problems for centering the ellipse (e.g. for rotation) -->
<s:Ellipse height="4" width="4" horizontalCenter="0" verticalCenter="0" >
<s:fill>
<s:SolidColor color="0x00FF00"/>
</s:fill>
</s:Ellipse>
</s:Group>
I populate a Dictionary to keep a track of all the component created. Finally I nullify all that I can to hint the garbage collector.
Now I have a function to empty the Dictionary (componentBag below) when we want to unload the images:
protected function button1_clickHandler(event:MouseEvent):void
for each ( var g : Group in componentBag )
((ImgPanel)(g.getChildAt(0))).img_.unloadAndStop(false);
((ImgPanel)(g.getChildAt(0))).image = null;
delete componentBag[g.uid];
g.removeElementAt(0);
this.removeElement(g);
g = null;
triggerGC();
PROBLEM: using profiler, the loading/unloading works once or twice and after the memory keeps increasing... And if I launch the application, wait for a while and do a load/unload, the garbage collection only recovers a few megabytes, far from what was allocated for displaying the images.
What am I missing? Is there a problem with loading a lot of images? Has anyone done this?
In attachment is the full test code, the ImgPanel goes inside a 'views' package
Thanks to Anton_AL, I finally solved this problem by using an URLLoader AND a plain Loader:
var loader: URLLoader = new URLLoader( );
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onLoadingComplete );
loader.load( new URLRequest(file.url) );
private function onLoadingComplete( e: Event ):void
var loader: Loader = new Loader( );
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onParsingComplete );
loader.loadBytes( e.target.data );
private function onParsingComplete( e: Event ):void
var img: BitmapImage = new BitmapImage( );
img.source = (e.target.content as Bitmap).bitmapData;
_images.push( img );
private function onImageLoaded( e:Event ):void
var img: Image = e.target as Image;
img.removeEventListener( Event.COMPLETE, onImageLoaded );
_images.push( img );
See Anton's thread here: http://forums.adobe.com/message/2358653#2358653
Similar Messages
-
Trying to load MP3 from desktop to AIR application
I'm trying to load an MP3 file into an Air application.
Here's some code. The first 2 lines are in my constructor
fileToOpen.browseForOpen("Open", [new FileFilter("MP3",
"*.mp3")]);
fileToOpen.addEventListener(Event.SELECT, fileSelected);
private function fileSelected(event:Event):void
var stream:FileStream = new FileStream();
trace(fileToOpen.nativePath);
// sound = new Sound(new URLRequest(fileToOpen.nativePath));
// trace(sound);
stream.open(event.target, FileMode.READ);
trace(stream.bytesAvailable);
sound = new Sound(stream.readBytes(stream.bytesAvailable));
channel = sound.play(00000);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
Using URLRequest gives me the error Error #2044: Unhandled
IOErrorEvent:. text=Error #2032: Stream Error. I can't seem to load
a file when I give it the full path. Then with the file stream, I
don't even know what I'm doing. I don't know which method I'm
supposed to use to load the file into a sound object. Please
help...I figured it out. I tried url instead of nativePath for the
file object and it worked. -
Loading JPEG/Gif images causes Out Of Memory Error
Hello Java gurus, please shed some light on this.....
I am not a java newbie, but I am a java newbie in the area of dealing with graphics. I am using JDK 1.4.2_01 on Win XP with 2.4ghz and 512 RAM. When I try to read in a (or a few) JPEG image into a JLabel using ImageIcon, I get an out of memory error everytime. This happens whether I am reading the image out of a jar file or out of a local directory. The JPEG's are 8.5" x 11", and range between 150kb to 900kb. I am trying to load approximately 10 images in a JTabbedPane using new JLabel(ImageIcon) on individual JPanels (one JPanel for each JPEG). Now I get the java.lang.outofmemory error whether I try to load 1 image or 10 images. Anyone got a clue as to what I am doing wrong? I actually do get one image loaded before the error gets thrown. So I do know that it is trying to load the right image. What is going on here? Is it an ImageIcon problem, or are there others who have run into this. It has brought this project to a grinding halt, and I had thought this would be the easier part!!!! Please help me out gurus! Thanks!What options/values are you suggesting that I set? Or do you mean something else? Thank you for any ideas that can help me solve this problem. I never had any issues dealing with using ImageIcon for toolbar button graphics (file sizes of 1-3kb), but now with dealing with full page graphics I have run into a brick wall with this out of memory error.
-
AIR runtime Memory Leak?
Hi,
I have an app developed with AIR 3.7 for iOS (iPad)
The app gets very sluggish after a while, eventually crashes.
I've been -very- careful to pool objects where possible and cleanup / nullify all objects once they're not needed any more.
Profiling the app in Scout returns a pretty stable memory profile (the peaks and the lows translate very well to what's happening on screen)
Simultenously profiling the app using XCode's Instruments, shows me that the memory consumption off the app constantly rises up to the point the systems spends more time throwing memory warning than anything else.
Here are screenshots of both profilers: they show as3 memory usage being pretty stable, on the app level, memory keeps rising...
https://dl.dropboxusercontent.com/u/608333/AIR_memory_leak.zip
If AS3 is not leaking any memory (according to scout), but the app is (according to Instruments), would I be right assuming there's a memory leak in the AIR-runtime itself?
thanks for your feedback!
bart.ok, lots of trial and error has showed me the following:
There are two issues when loading assets using the Loader Class with its LoaderContext set to ImageDecodingPolicy.ON_LOAD.
These issues typically arise in a magazine-like app, where many images are loaded and unloaded continously.
Issue 1:
When initializing a load() on a Loader class with LoaderContext to ImageDecodingPolicy.ON_LOAD, all image decoding seems to be queued in a seperate thread. With several large images, especially on mobile devices, the time to crunch through a queue like this can easily go into dozens of seconds. During that time, some of the loaders can be unloaded, cleared, nulled and deleted. Yet, the loader isn't removed from the decoding queue.
In other words: once you fire the 'load' method on a Loader instance, you're not able to cancel the decompression process, even though the decompression might not even have started yet, as queued by other decompressions.
Issue 2:
When a Loader instance is unloaded, cleared, nulled and deleted while its decompression is still queued and not yet fully decompressed, there seems to be a memory leak. With several dozens of images loading and interupting the loading, you'll notice a difference in memory consumtion when comparing memory output in Scout and in Instruments. Both memory graphs build up very similar yet after the runtime's garbarge collection kicks in, the memory graph in Instruments seems to not release memory fully. Consumption gradually rises until the app eventually crashes.
https://dl.dropboxusercontent.com/u/608333/AIRMemoryLeakExample.zip
This example app allows you to create loaders in bursts by touching the screen.
You'll instantly see the massive waiting times for decompression, despite the fact there's only a few Loader instances in memory at the same time. After several short bursts and wait-a-bit-for-decompression-to-catch-up, you should also notice the difference in memory profiling between Scout and Instruments.
I managed to work around both issues by making a LoaderQueueManager class.
This class instantiates and returns a Loader instance, queues these instances and tracks its onComplete handler. Only when one loader is finished loading, the next loader starts loading. This way, you never have different instances trying to simulataneously decompress their content. As such decompressions are never interrupted and loaders can also be de-queued. This practically speeds up decompression dramatically, since images that are removed won't get decompressed in vain. Memory Leaks also don't occur, since not a single decompression is ever interupted.
This solution only works with content loaded locally.
Hope you can get somewhere with this,
and hopefully, you find a fix in one of the next AIR releases.
best,
bart. -
Loading/unloading movie/image in actionscript
Hi I'm trying to load an image on the fly in flash which is
no problem, but then when i need it to unload it doesn't and i get
an
*** Security Sandbox Violation ***
Connection to
file:///C|/Documents%20and%20Settings/Administrator/Desktop/Latest%20Versions/High%20res% 20newsreader/
halted - not permitted from
http://MYSERVER/test/tfl.gif
-- Remote SWFs may not access local files.
Why does this happen? why would it load but not unload?
The load code is
_root.createEmptyMovieClip("box", 1);
_root.box.createEmptyMovieClip("pic_mc", 2);
_root.box.pic_mc._x = -40;
_root.box.pic_mc._y = 0;
_root.box.pic_mc.loadMovie( "
http://MYSERVER/test/tfl.gif"
and unload is
_root.box.pic_mc.unloadMovie();it has to do with settings in the player. For security
reasons, you can only load data from within your domain. Local
domain is always 127.0.0.1 or localhost. don't use
http:// inside your call to loadMovie. Always
use the local method (relative path from the current flash file
i.e. /test/tfl.gif) and make sure that the images are local. By
using that
http://MYSERVER, flash thinks that the
domain for the current running movie is MYSERVER and not localhost
therefore, it will restrict all access to local files. Now, if you
put the flash file up on MYSERVER, chances are like wwscoper just
pointed out, it will work perfectly because localhost and MYSERVER
refer to the same masked IP. -
Work offline, load large saved page, program not responding, memory leak.
Firefox 4 not responding. To create: Load a largish HTML page (Kindle or PS3 pages from www.amazon.com), save as web page complete. Disconnect from Internet. Load saved page (work offline checked or not). Peruse page 1-2 minutes, note CPU and PF usage. CPU usage will go to 100% & PF usage rise rapidly
Firefox 4 not responding. To create: Load a largish HTML page (Kindle or PS3 pages from www.amazon.com), save as web page complete. Disconnect from Internet. Load saved page (work offline checked or not). Peruse page 1-2 minutes, note CPU and PF usage. CPU usage will go to 100% & PF usage rise rapidly
-
Google map loading delay in Adobe AIR application
Hi,
When I try to load Google map API on AIR application,it is taking too much time to load and the application freezes for 50-60 seconds.But it is working fine in normal flex applications.Please give a solution for this.See this bug for more information and a workaround: http://code.google.com/p/gmaps-api-issues/issues/detail?id=2750
-
It appears that when using the hot deploy functionality on Weblogic
6.2 to redeploy an EJB application .ear that all previously loaded
classes are untouched - creating a huge memory leak. The weblogic
generated stub classes are never touched, even though new copies are
loaded into memory. After numerous hot deploys, I eventually get an
out of memory error. Is there some way to force the unloading of
these classes? Is this fixed on WL 7 maybe ?I will contact bea support as well, but any ideas if this fix is
resolved in base WL 7.0, or is there a SP for 7.0 that includes this
fix too?
Thanks,
Terry
==========
Rajesh Mirchandani <[email protected]> wrote in message news:<[email protected]>...
This is fixed over SP3 and is in SP4. Pls contact [email protected]
Jared Rodriguez wrote:
It appears that when using the hot deploy functionality on Weblogic
6.2 to redeploy an EJB application .ear that all previously loaded
classes are untouched - creating a huge memory leak. The weblogic
generated stub classes are never touched, even though new copies are
loaded into memory. After numerous hot deploys, I eventually get an
out of memory error. Is there some way to force the unloading of
these classes? Is this fixed on WL 7 maybe ? -
Memory leaks in GC or something else on iOS
Hello.
I am making a game by Adobe AIR for iOS. My application has a memory leak bug with using only iOS.
So, I have some questions.
Why is it different using memory size of between Scout and Instruments VM Tracker (Dirty size) ?
Why is the difference increased between Scout and VM Tracker?I think, AIR makes memory leaks on GC when iOS alerts a low memory warning.
Can I catch GPU memory size ?
Rendering mode is 'gpu'.
I don't use Stage3D.
I think it is 'IOKit' dirty size of VM Tracker. Its right?
Scout gives no memory leaks. Instruments VM Tracker gives 50MB leaks for 20min.
1min ago. 162MB
20min ago. 162MB
Instruments 220MB -> 272MB
Scout overhead memory was about 1kB/min increasing.
I am sorry I have no small code to reproduce.
Environment:
iPad mini iOS7.0.4
AIR 3.9.0.1030Hi!
I think the virus did modify or delete some system files so are not able to boot in safe mode, print documents and so far.
Furthermore I must agree Raver. The best way would be to reinstall Windows with the recovery disk. This takes only few minutes but safe your data before. The HDD will be completely formatted.
If have reinstalled Windows, you should first install all Service Packs and Hotfixes (visit the Windows update website).
And dont forget to install a antivirus program like AntiVir (freeware).
Bye -
Open PS (CS-CS4) and load image from flex/air application?
Hello,
(Not sure wether to post this in the AIR forum or the FLEX forum?)
I am at a loss on how to get my simple application to work. I have a small desktop air application that simply opens Photoshop and runs an action. I used switchboard and the application ran great on PC and MAC. However it only worked for CS3, and CS4 not CS or CS2?. Plus the size of switchboard was a bit large for my small app. I am willing to live with that though . I am using Air with Flex and wanted to know if perhaps there is a beter approach? All the application does is open photoshop, loads an image, and runs an action. Can I do this for all versions of Photoshop using switchboard? Can I do this without switchboard and just use javascript. The big issue is the Air app needs to open Photoshop, and most of the examples have me open PS first and then execute a script located in the PS directory. This needs to work outside of the PS directory. Any examples are appreciated.
I have looked at the following:
- SwitchBoard : only works for CS3-CS4 (on my tests)
- PatchPanel: same issue, plus seperate SDKs
- ExtendScript: requires script to be run from PS not AirOf course you may have some unstated reason for doing this in Air, but if not...
Google photoshop droplet....
Bob -
We are implementing an AIR application that loads thumbnails
from the hard drive and uploads them to a remote server.
When bringing in large images, for example, when importing
five 2MB files into Image objects:
Flex reports that it is using 55MB
Windows reports using 220 Meg (viewing memory usage of
adl.exe in task manager)
After deletion of these image objects, the memory stays
allocated!! It is released when the application is closed.
Two issues I see:
1. Huge memory usage for image objects (I understand that JPG
files are exploded into BMPs). It limits our ability to load 10's
or 100's of images.
2. Bad Memory leak
OTHER THINGS WE TRIED:
1. Displaying images as inline html IMG tags.. Same memory
usage!
2. Taking a snapshot of the image and displaying that.
Problem, used way to much CPU
I hope these issues will be fixed before release time or we
are hosed.
PLATFORM: Windows XP Professional, service pack 2Hi
Have you tried the FB3 profiler to investigate why memory is
not getting deallocated?
You can use the loitering objects panel to track the back
references for the objects in memory. If you find that image object
is not being referenced by anything else. Can you file a bug at
http://bugs.adobe.com/flex
with a small test case.
Also as you know that jpg will be translated into bitmap. The
amount of memory required will be determined by the pixels in the
image. Each pixel will be 4K
Thanks,
Gaurav Jain
Flex SDK Team -
Adobe AIR memory leak loading SWFs
I was plagued by a memory leak that would crash my application after a few hours. The application had worked fine in the past but now was having issues and I thought it might have to do with using newer SDK's.
In the end I discovered that if I loaded external swf that had been compiled in debug mode, they would not clear completely on unload and cause a memory leak.
Compiling in release mode fixed the issue. Spent 3 days trying to figure it out.Any chance you can check that out with the latest AIR?
Either way, it sounds like a bug, please report it at http://bugbase.adobe.com/ and then report the bug number here.
If you're able to provide a reproducable case that would really increase the chance that we can do something about it.
Thanks,
roymeo -
Display image in standalone AIR application
I have loaded images and like to display image in standalone AIR application. But I cannot get it work. The code as follows:
private function ImageLoader(url:String):void
var request:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
loader.load(request);
private function loaderComplete(event:Event):void
var scaleFactor:Number = 1;
var uic:UIComponent = new UIComponent();
try
var bmp:Bitmap = event.target.content as Bitmap;
var bmd:BitmapData = bmp.bitmapData; //Bitmap(event.target.content).bitmapData;
var scaledBMD:BitmapData = new BitmapData(400, 400);
var matrix:Matrix = new Matrix();
matrix.scale(scaleFactor, scaleFactor);
scaledBMD.draw(bmd, matrix, null, null, null, true);
uic.x = 40;
uic.y = 40;
uic.addChild(new Bitmap(scaledBMD));
catch (errObject:Error)
trace(errObject.message);Found answer by adding mx:Canvas and add
iconCanvas.addChild(uic);
after
uic.addChild(new Bitmap(scaledBMD));
<mx:Canvas id="iconCanvas" width="10" height="10" horizontalScrollPolicy="off" verticalScrollPolicy="off" x="0" y="0" clipContent="false"/>
Is anyone create "Canvas" by using new Canvas and get it works? example:
var canv:Canvas = new Canvas(...); -
Loading External Images Causes Memory Leak
I have been working on an Actionscript 2.0 project that basically loads external images.
Everytime i load and unload a new image, memory increases to 1 or 2 MBs
If all the images are in cache, then it increased to 4 or 8 KBs
In the unloading of images, I have removed loader and the container of the image.
Any thoughts why it is behaving like that?
Please find the sample code snippet below.
btn_load.onRelease = function()
loadImage();
btn_unLoad.onRelease = function()
unLoadImage();
var mcListener:Object = new Object();
var container1:MovieClip;
var mcLoader:MovieClipLoader;
var loader_reference = this;
var n=0;
function loadImage(){
var image_arr = ["http://xyz.com/image1.png","http://xyz.com/image2.png","http://xyz.com/image3.png","http:/ /xyz.com/image4.png","http://xyz.com/image5.png"];
var image_url = image_arr[n];
if(n==image_arr.length-1) {
n=0;
}else{
n++;
container1 = loader_reference.createEmptyMovieClip("container1", loader_reference.getNextHighestDepth());
mcLoader = new MovieClipLoader();
mcLoader.removeListener(mcListener);
mcLoader.addListener(mcListener);
mcListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
mcListener.onLoadInit = function(target_mc:MovieClip):Void {
target_mc._x = 300;
target_mc._y = 200;
target_mc._width = 300;
target_mc._height = 250;
mcLoader.loadClip(image_url, container1);
function unLoadImage(){
mcLoader.unloadClip(container1);
mcLoader = null;
container1 = null;
removeMovieClip(loader_reference.container1);
Thanks in advance.that code should only execute once. fix that.
-
Good evening all,
I think this is a complex issue.
I have adobe air application which loads a SWF I made.
Inside this SWF I have used the "component LOADER" to load
something with "ContentPath=image.jpg" for example.
But the swf loaded in the Adobe air works, but does not load
the "ContentPath image"...
(it does load and display it when it this swf is run outside
adobe Air)
I need it to be dynamic like this, so if eventually I Include
it in the package it won't help much...
I just intend to replace an image background from this loaded
swf file!
Thanks!
Edit:
At this time of the editing, I fear and realize
something....I have been using Actionscript2 for the .SWF file,
could it be why it does not works???
If its problematic, is there a simple way like telling it to
read actionscript2, rather than transforming everything??
edit2:
I found this on the official AIR FAQ:
Will Flash version 8 and below SWF files run in Adobe AIR?
Yes. However, the Adobe AIR APIs are only exposed to Flash
content via ActionScript 3 / AVM2, and thus Flash 8 / AVM1 SWFs
will be able to run, but they will not have direct access to the
Adobe AIR APIs.
source:
source
faq Adobe
it seems it should works!!??
Edit3:
nope I confirm at least some code made in Actionscript2
works.
I am sure this code needed to be changed for working in
actionscript3, so "actionscript2" code works in Adobe Air.
The problem of not loading my image must come from something
else!!??Good Morning all!
Hilarious....
I tried so much to think maybe Adobe Air does not like a SWF
using actionscript2, or it does not load any "external image from a
swf", etc...
None of that!
I just in FLASH in the ComponentLoader....I did put simply
the ContentPath at "myimage.jpg"....
Of course I had to use the absolute path like
"c:\\myfolder\\myimage.jpg"
Of course aswell it works now!!!
Maybe you are looking for
-
Need help configuring Aiport Extreme A1034 to optimize network signal.
Greetings, I am a very loyal mac user from back in the days of the Quadra 650. I have torn apart and fixed most macs for the last 13, but I must say configuring this wireless network has got me stumped. Any help would be gladly appreciated. I went fr
-
OMW supports sybase ASE 15 to Oracle 10g migration?
Hi, I want to migrate data from Sybase ASE 15 to Oracle 10g. Can i use OMW for this purpose if not then what is the other way of doing it? Kind regards Ankit
-
Hi, does anybody know, where the Information of the estimated_rows (e-rows) Output comes from? I would like to auto check, when a explain uses wrong statistics. I know that is inside the dbms_xplan.display.display Package but i would like to use it o
-
Pavilion Slimline s3760a: Cloning the Hard drive to replace with larger drive
Product Name:Pavilion Slimline s3760a OS: Vista Hi All, I'm Turina, just joined the forum think I'm posting in the right place but let me know if I'm not please. So we've had our computer for several years, the hard drive is in the red so am swapping
-
Hi, Is there any possibility to find assets that aren't used in any Final Cut Pro project or Final Cut Server production. I want purge my assets and I want be sure I won't delete any media/assets used by project/production. I found theese metadata gr