View Full Version : Memory Usage - how much is too much?
02-12-2010, 02:23 AM
I've started to use System.totalMemory to check how much memory my flash games are using and to check for leaks.
I realise that it's subject to the user's computer, but generally, what is the number when I should start to worry that the memory usage is too much?
There can't really be a good answer to that besides the famous "it depends".
02-12-2010, 02:25 PM
I think one of the main "depends on" cases ASWC mentions is : "Is my application leaking memory?"
I think when it comes to Flash the biggest issue with memory is less often how much you expect to use in a normal application but whether or not you're ever getting rid of it when you think you should.
More often, you'll be concerned about whether or not your app is causing an enormous processor hit. That's not something Flash has an internal tool to tell you, unfortunately.
02-12-2010, 02:42 PM
I like to use net.hires.debug.Stats to keep track of my app's memory and frame rate. It's really nice and easy to add (and just as easy to remove when you don't need it anymore).
As maskedMan said, I think you need to worry about memory leaks more then total memory usage. Usually your app won't use too much memory if it only uses as much as it needs.
The interesting thing is, how you manage your memory can really effect the processor usage. Garbage collection and instance creation can really slow your app down, so even if you take care of all your memory leaks, you may slow your app down a lot for a different reason.
Recycling is the best solution I've found for all the problems mentioned above. Save and reuse objects and assets as much as possible instead of throwing them away and remaking them later. BitmapData objects are probably the easiest to recycle in my experiance and they tend to take up biggest piece of memory as well.
02-12-2010, 03:31 PM
By the way, I just had a good opportunity to put into practice what I just said in my post above.
You see, I have an Adobe Acrobat image icon that I'm going to be using all over this application. So I have that image in my library with an Export for ActionScript class of com.tenoz.display.Acrobat which extends BitmapData.
Now instead of creating a new instance of this every time I need it (even though it's just a 28X29px icon and won't make much of a difference either way) I'm going to create a singleton out of it (the only good use I've found for singletons is in the case of BitmapData objects). This way I can reuse the same data everywhere without making tons of copies.
public final class Acrobat extends BitmapData
private static var _instance:BitmapData;
public static function get instance():BitmapData
if(_instance == null) _instance = new Acrobat();
public function Acrobat()
BAM! Easy memory management. Whenever I need this icon I just say new Bitmap(Acrobat.instance);
and if I need to mess with the BitmapData for some reason, I can still use new Acrobat() at any time to get a separate copy.
02-12-2010, 05:28 PM
Excellent points, tomMalufe!
On the topic of how you monitor memory usage, one thing to keep in mind is that the preview player, in which you simply publish with Ctrl+Enter, uses enormous amounts of memory compared to the flash player running in the user's browser.
I once nearly choked when I saw an app in the preview player reporting usage of over 70MB of RAM. Then once I saw the same app in the browser I noticed it used about 5MB-7MB at a time.
vBulletin® v3.8.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.