views:

758

answers:

2

Hi,

I am looking for some advice on memory usage on mobile devices, BlackBerry in particular. Using some profiling tools we have calculated a working set size in RAM of 525kb. Problem is we don't really know whether this is acceptable or too high.

Can anyone give any insight into their own experience with memory usage on BlackBerry? What sort of number should we be aiming for?

I'm also wondering what sort of things we should be looking out for in particular to reduce memory usage.

TIA

A: 

If I'm not mistaken, Blackberry apps are written in Java... which is a managed environment, which means really the only surefire way to use less memory is to create fewer objects. There's not a whole lot you can do about your working set, I think, since it's managed by the runtime (which is actually probably the point of using Java on devices like this).

DannySmurf
+2  A: 

512KB is perfectly acceptable on the current generation of BlackBerrys devices. You can take a look at JBenchmark to see the exact JVM heap you can expect for each model, but none of the current devices out there go below 20MB of heap. Most are much larger than that.

On JBenchmark you can choose the device you are interested from a drop down on the right side of the page. Then, navigate to the JVM Tab for the device.

When it comes to reducing memory usage I wouldn't worry about the total bytes used for this application if you are truly inline with 525K, just about how often allocation/reallocation is required. Try to pool/reuse objects as much as possible, avoiding any unneeded allocation. For instance, use the StringBuffer class to concatenate strings instead of operators as multiple String objects will be created for each concatenation using the operator, where a StringBuffer will just put the characters in an array and only expand when needed. Google is a good way to find more tips.

Finally, relying on profiling tools, which the BlackBerry JDE has, is a very important part of understanding exactly how you can optimize heap memory usage.

Fostah
Thanks for some useful comments Fostah. One thing I would like to point out though is that the compiler will turn String concatenation into StringBuffer in many cases, I have often found the debugger going into StringBuffer method where nothing like it was present in my own code.
roryf
That's interesting. I'm still relatively new to the BlackBerry platform. I've spent a substantial amount of time doing General J2ME programming and you don't always see these useful optimizations from every manufacturer.
Fostah
I'm not sure what compiler it is that does the optimisation, we have a 3-step build process that uses the WTK javac first, then ProGuard for obfuscation and optimisation, and then the rapc compiler. Could be any of those, but my bet would be ProGuard or rapc.
roryf
Oh yeah, that makes sense as newer version of ProGuard does a lot of optimization under the hood.
Fostah