Quantcast
Channel: Adobe Community : All Content - AIR Development
Viewing all articles
Browse latest Browse all 2954

memory leak when pushView an popView

$
0
0

Hello to community!

 

I am having problems of memory leaks with an app I had build. After using it for 30-40 min it begin to go slow and slow.

 

The app show images as a catalog, but when I push and pop the views my memory rise a lot.

 

I think I am deleting all my oibjects setting them to to null and disposing all de bitmapdata that I use so I think that the problem should not be there.

 

I have 3 views in my app menuView.mxml,categoriesView.mxml and productsView.mxml.

 

My App begin in my pc (not in tablet) with TotalMemory: 47Mb and Private Memory : 88 MB

 

After pushing and poping the views for 5 times I get TotalMemory: 61Mb and Private Memory : 101 MB

 

Imagine if I do this for 20 times, all the app begin to go very slow in my Ipad or my Samsung Galaxy Tab.

 

Why is this happening? I have no idea how to solve this.

 

Thanks a lot!!

 

I put some code below.


 

Whe I am in menuView i use the following code to push the view from menuView to categoriesView

 

protected function button3_clickHandler(event:MouseEvent):void

            {

                if((FlexGlobals.topLevelApplication.getIdClienteServidorCompraActual( )!=null)&&(FlexGlobals.topLevelApplication.getIdClienteServidorCompraA ctual()>0))

                {

                    navigator.pushView(categoriesView);

                }

            }

 

Whe I am in categoriesView i use the following code to push the view from categoriesView to productsView. In this view i have 3 button for each category.

 

protected function buttonC1_clickHandler(event:MouseEvent):void

            {

                //Categoria general con todos

                var ab:ArrayCollection =  getIdAmbienteServidor();

                cleanMemory();

                navigator.pushView(productsView, null);

            }

 

private function cleanMemory():void

            {

                result.splice(0);

                result = null;

                System.gc();

            }

 

Whe I am in productsView I use the following code to pop(I USE PUSH INSTEAD OF POP DUE TO DIFFERENT OPTIONS I HAVE) the view from productsViewto categoriesView .

 

 

protected function button1_clickHandler(event:MouseEvent):void

            {

                cleanMemory();               

                navigator.pushView(menuView);        

            }

 

private function cleanMemory():void

            {

                if(image1 != null)

                {

                    image1.source = "";

                    if(image1.bitmapData != null)

                    {

                        image1.bitmapData.dispose();

                    }

                }

                if(image2 != null)

                {

                    image2.source = "";

                    if(image2.bitmapData != null)

                    {

                        image2.bitmapData.dispose();

                    }

                }

 

                if(result != null)

                {

                    result.splice(0);

                    result = null;

                }

                if(result1 != null)

                {

                    result1.splice(0);

                    result1 = null;

                }

                if(result2 != null)

                {

                    result2.splice(0);

                    result2 = null;

                }

                dbConnection = null;

                object1 = null;

                object2 = null;

                dataToSave = null;

                cGreyImageSmallAsset = null;

                cRedImageSmallAsset.bitmapData.dispose();

                cRedImageSmallAsset = null;

 

                cOrangeImageAsset.bitmapData.dispose();

                cOrangeImageAsset = null;

 

                cGreenImageAsset.bitmapData.dispose();

                cGreenImageAsset = null;

 

                cPinkImageAsset.bitmapData.dispose();

                cPinkImageAsset = null;

 

                cBlueImageAsset.bitmapData.dispose();

                cBlueImageAsset = null;

 

                cGreyImageAsset.bitmapData.dispose();

                cGreyImageAsset = null;

 

                cRedImageAsset.bitmapData.dispose();

                cRedImageAsset = null;

 

                cGreenImageSmall = null;

                cOrangeImageSmall = null;

                cPinkImageSmall = null;

                cBlueImageSmall = null;

                cGreyImageSmall = null;

                cRedImageSmall= null;

                cGreenImage = null;

                cPinkImage = null;

                cBlueImage= null;

                cGreyImage = null;

                cRedImage= null;

                cOrangeImage= null;


                System.gc();

            }

 

I load the images with.

 

private function setImages():void

            {               

                //var width:Number = FlexGlobals.topLevelApplication.width;

                if(object1!=null)

                {                   

                    //var widthImage1:Number = (width/2)-80;

                    //image1.width = widthImage1;

                    panelLeft.visible = true;

                    buttonLeftMore.visible = true;

                    image1.source = "file://" + File.applicationStorageDirectory.nativePath + "/b"+object1.idArchivo+"_500.jpg";

                    setObject1MainTexts();

                }

                else

                {

                    image1.source = "";

                    panelLeft.visible = false;

                    buttonLeftMore.visible = false;

                }

                if(object2!=null)

                {   

                    //var widthImage2:Number = (width/2)-80;

                    //image2.width = widthImage2;

                    panelRight.visible = true;

                    buttonRightMore.visible = true;

                    image2.source = "file://" + File.applicationStorageDirectory.nativePath + "/b"+object2.idArchivo+"_500.jpg";

                    setObject2MainTexts();

                }

                else

                {

                    image2.source = "";

                    panelRight.visible = false;

                    buttonRightMore.visible = false;

                }

            }


 

Whe I am in categoriesView i use the following code to pop(I USE PUSH INSTEAD OF POP DUE TO DIFFERENT OPTIONS I HAVE)the view from categoriesView to menuView.

 

protected function button1_clickHandler(event:MouseEvent):void

            {

                cleanMemory();

                navigator.pushView(menuView);

            }

 

private function cleanMemory():void

            {

                result.splice(0);

                result = null;

                System.gc();

            }

 



Viewing all articles
Browse latest Browse all 2954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>