5 Replies Latest reply on Nov 5, 2009 1:13 AM by Bertrand G.

    Serious memory issues




      I have serious problems with my Adobe AIR application


      It loads 1000 png icons 32x32 and eats 250 Mb of RAM


      The code is following:


      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                     import mx.collections.ArrayCollection;
                     import mx.events.FlexEvent;
                     import flash.filesystem.File;
                     var imagesFolder = "data";
                     [Bindable] var images: ArrayCollection = new ArrayCollection;
                     function LoadImages( )
                          // determines, where icons are
                          var folder: File;
                               In this case, 70 Mb of RAM is taken by application
                          folder = File.applicationDirectory.resolvePath( this.imagesFolder );
                               In this case, 250 Mb of RAM will be taken
                          //folder = File.applicationDirectory.resolvePath( "C:/temp" );
                          if ( folder.isDirectory )
                               var files: Array = folder.getDirectoryListing( );
                               for each( var file: File in files )
                                    if ( ! file.isDirectory && file.extension == "jpeg" || file.extension == "jpg" || file.extension == "png" )
                                              this.images.addItem( file.url );
           <s:VGroup width="100%" height="100%">
                <s:Button label="load images" click="{LoadImages()}" />
                <s:List dataProvider="{images}" width="100%" height="100%" useVirtualLayout="false">
                          <s:TileLayout columnWidth="72" rowHeight="72" />
                                    <!--States must be included obligatory, because they are inside of List control, that needs this states-->
                                         <s:State name="normal" />
                                         <s:State name="hovered" />
                                         <s:State name="selected" />
                                    <mx:Image source="{data}" width="100%" height="100%" />


      I need to keep useVirtualLayout disabled, to avoid swaping the icons, during scrolling


      I have mentioned the following Magic-behaviour:

      • when icons folder is in the same folder, where application is (bin-debug), 70 Mb will be consumed after displaying the icons
      • when icons folder is somewhere else, e.g. C:/temp, application consumes 250 Mb of RAM


      Simple calculation of memory amount for 1000 RGBA bitmaps 32x32:

      32x32x4x1000 = 4 Mb


      Actually, Flex consumes 15-60 times more...


      Flex project with1000 icons in bin-debug folder is attached to this thread (Project-->Clean, Run).


      I'm stuck with this problem, please, help !

        • 1. Re: Serious memory issues
          Flex harUI Adobe Employee

          Use the profiler to see where all the memory is going.  How much does it eat if you only have 100 icons?


          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Serious memory issues
            Bertrand G. Level 1



            I have a similar problem while trying to load and unload images... the memory does not get restored, and the profiler shows all the memory is going to the component containing the image.


            I played a lot with the garbage collector to try to fix this with no success.

            my thread: Load / unload numerous images in air application (memory leak?)


            By the way have you properly removed the eventListener once each image that is loaded?


            I did a test with your files on a macOSX and with 1000 images, the app took a little above 16M... I guess you are using windows!

            Profiler says 1000 instances for a memory of 1432000 (99.73%)



            • 3. Re: Serious memory issues
              Anton_AL Level 1


                   You are right, i use Windows 7.


              I have overcomed this issues, and loaded and displayed icons are now take ~4Mb, as the theory says.


              Checkout my post here . It is russian, just see my last post.

              The main idea is using native classes for loading images.



              Adobe, please, take an eye to this issue

              • 4. Re: Serious memory issues
                Bertrand G. Level 1

                Oh, this looks very interesting and might actually solve my problem! I will try first thing tomorrow morning... until now I am still struggling with the garbage collector and disposing of all the objects.


                Thank you for the link!! Luckily we have a russian in our lab ;-)



                Yes! it works, thanks a ton! This issue was really killing me... Now I can recover the memory correctly after loading and unloading a lot of images.


                Message was edited by: Bertrand G.

                • 5. Weird behavior with 1000 images... the count is wrong!!
                  Bertrand G. Level 1

                  One thing is happening now with the code you provided:


                  when I load 1024 images (which are 8 times file copies of 128 images), only a portion of it get loaded (depending on speed between load and display, debug mode or not etc...)


                  - I localized the issue between the onLoadingComplete (which is called 1024 times) and the onParsingComplete which is called 409, 442 or 510 times... can be different each run...


                  I've strictly used the same methods. The only thing that I can think of is something happening when some files are strict copy (except filenames).


                  private function onLoadingComplete( e: Event ):void


                       var dispLoader: Loader = new Loader( );


                       dispLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onParsingComplete );

                       dispLoader.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 );