开发者

Adobe Air 3 iOS app memory leak issue maybe related to getDefinitionByName class

开发者 https://www.devze.com 2023-04-13 09:09 出处:网络
I\'m developing an application with adobe air 3 for ios and having low memory errors frequently. After ios 5 update os started to kill my app after some low memory warnings.

I'm developing an application with adobe air 3 for ios and having low memory errors frequently. After ios 5 update os started to kill my app after some low memory warnings.

But the thing is profiler says app uses 4 to 9 megs of memory. There are a lot of bitmap copy operations around and sometimes instantiates new bitmaps from embedded bitmaps. I highly optimized everything and look for leaks etc.

I watch profiler for memory status and seems like GC clears everything. everything looks perfect but app continues to get low memory errors and gets killed by os.

Is there anything wrong with this code below. Because my assumption is this ClassReference never gets off from mem开发者_运维百科ory even the profiles says memory is cleared. I used clone method to pass value instead of pass by ref. so I guess GC can collect that local variable. I tried with and without clone nothing changes.

If the code below runs 10-15 times with different tile Id's app crashes but with same ID's it continues working.

Is there anyone who is familiar with this kind of thing?

tmp is bitmapData

if (isMoving)
{
tmp=getProxyImage(x,y); //low resolution tile image
}
else
{
strTmp="main_TILE"+getTileID(x,y);
var ClassReference:Class =  getDefinitionByName(strTmp) as Class; //full resolution tile image //something wrong here 
tmp=new ClassReference().bitmapData.clone(); //something wrong here
ClassReference=null;
}
return tmp.clone();

Thanks for reading. I hope some one has a solution for this.


You are creating three copies of your bitmapdata with this. They will likely get garbage collected eventually, but you probably run out of memory before that happens.

(Here I assume you have embedded your bitmapdata using the [Embed] tag)

tmp = new ClassReference()

// allocates no new memory, class reference already exists
var ClassReference:Class =  getDefinitionByName(strTmp) as Class;

// creates a new BitmapAsset from the class reference including it's BitmapData.
// then you clone this bitmapdata, giving you two
tmp = new ClassReference().bitmapData.clone();

// not really necessary since ClassReference goes out of scope anyway, but no harm done
ClassReference=null;

// Makes a third copy of your second copy and returns it.
return tmp.clone();

I would recommend this (assuming you need unique bitmapDatas for each tile)

var ClassReference:Class =  getDefinitionByName(strTmp) as Class;
return new ClassReference().bitmapData.clone();

If you don't need unique bitmapDatas, keep static properties with the bitmapDatas on some class and use the same ones all over. That will minimize memory usage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号