What is the maximum amount memory Adobe AIR can ut

2019-03-25 08:42发布

问题:

I've been doing some rapid prototyping for a game I'm thinking of building. one of the main things i want to do is map generation for a tile type map. While generating the map i end up using large amounts of ram. I'm building the map as an array of random integers for my test. When i try to generate maps of a large scale flash gives me the out of memory error:

Error: Error #1000: The system is out of memory.

I've already figured i could write to a file instead, to solve that problem. but does anybody know the actual maximum size? I've tried searching around to no avail.

Activity monitor reports that ADL is using around 500MB "real memory" and around 700MB "virtual memory". The System.privateMemory property seems to match the "real memory" value.

as a side note i'm developing in OSX Snow Leopard (64) with 8gb ram

EDIT:

Here the example test i am running

var ba:ByteArray = new ByteArray();
for(var i:uint = 0; i<100000000; i++)
{
    ba.writeInt(int(Math.random()*100));
}

trace("end", ba.length, System.totalMemory);

This example runs fine, afterwards the total memory property reports around 500MB of ram used. Now increasing the target value to 400,000,000 i eventually receive the 'out of memory' error.

note: Testing in Flash CS5.5 with the timeout set to 120 seconds (the test never reaches that time)

EDIT:

i've created a better testing example:

var i:uint = 0;
var loopLength:Number = 500000000; // 500,000,000
var ba:ByteArray = new ByteArray();

for(i=0;i<loopLength;i++){
    try{ba.writeInt(1);}
    catch(e:Error){
        MEM_TI.appendText(e.message);
        break;
    }
}    

ba.position = 0;
MEM_TI.appendText("\nTM: "+System.totalMemory+" FM: "+System.freeMemory+" PM: "+System.privateMemory+" BALENGTH: "+ba.bytesAvailable/4);

When i run this script from a browser, stand-alone debugger or AIR i get roughly the same memory usage readouts (which i know vary anyway). What is constant however is the final length of the byte array:

Browser (Firefox): TM: 540413952 FM: 19116032 PM: 562573312 BALENGTH: 134217728

Stand-alone: TM: 540577792 FM: 1810432 PM: 545361920 BALENGTH: 134217728

AIR (2.6): TM: 5410816 FM: 1159168 PM: 551464960 BALENGTH: 134217728

My testing methods might not be perfect, though i dont know how to do deeper profiling.

回答1:

As of Windows 7, and AIR 3.3 Adobe AIR apps are limited to around 1GB memory allocation. This will change once Adobe AIR becomes 64-bit. Adobe plans to do 2 different rewrites of the platform. The first rewrite will take place by the end of 2012. This rewrite will add multithreading to the Flash, AIR runtimes. This first rewrite probably will not fix the existing memory allocation issues and limitations. But the second rewrite will for sure which is coming in 2013 codenamed "Next". This rewrite is the "ActionScript 4.0" which includes 64-bit runtime, memory allocation enhancements, programming language enhancements, new compiler, and a huge improvement in performance. Until then do not try to allocate more than 900MB of RAM at the risk of the app simple crashing without warning.



回答2:

There's no details provided, but my gut feeling would be that the problem you're having is not lack of memory (which your system has ample) but suboptimal and/or faulty algorhythms. You probably need to rethink the way you generate the maps and also be sure that you're not ending up in an infinite loop somewhere.

If you post more details (possibly in another question) maybe we can be more helpful.



回答3:

Not sure if you're already on this but you can play around with the property System.totalMemory to get a live readout of the amount of memory that flash is using at that moment (all instances of Flash Player/adl, so watch out if you have a browser open with flash content playing)

Link: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/System.html#totalMemory

It may help to display the memory used in a textfield on the screen or add it to a watch list as you debug to find out exactly what classes/methods are eating up all that ram! You could also take readings of the totalMemory and put in breakpoints to stop the program when it hits a certain threshold.

It may also help to only generate a map large enough for what is on the screen, and generate further territory as the player moves in a certain direction and culling the territory that is out of bounds. This form of culling is popular in 3D games to eliminate unseen geometry but will also help for your problem of massive maps and limited memory.



回答4:

I've investigated this issue a bit recently and indeed there seems to be a memory threshold (dependent on the platform and, it seems, especially on the OS) after which an AIR app will become unresponsive / crash. (I didn't manage to get the out-of-memory Error #1000 though). I've opened an Adobe bug here: https://tracker.adobe.com/#/view/AIR-4198476. Hopefully we'll get some more info from Adobe soon.