Monday, July 13, 2009

Memory optimisation for low end devices

So far so good. feels great to be back again.

For last few days my life was in turnmoil. Project deliveries , documentation , new project details blah blah blah.

In midst all these i got request from my client that the application was not being supported by low end devices due to memory constraints.

For those who are unaware , i had been working on a mobile application , over j2me platform , which is basically sms base servce application. It has around 50 different flows along with good UI and other flashy things in it which hogs on to memory like anything.

Now my client wants all these features to be there , and also he wants the application to work smoothly on devices with memory as low as 200KB.

So this way my journey started towards memory optimisation of the application which i myself made.

Now as you all know every developer likes his application like his own kid. So it becomes really difficult to find fault in it.

Anyways this started my voyage towards optimising my kid.

I searched web and got a lot of things and tried all of them. some helped some dint. The final outcome was that application was still throwing out of memory error on low end devices.

Then i thought lets give our code a closer look.

And that was an eye opener, there were a lot of things which needed to be done and couldnt have been possibly told by anyone.
Not going deep in to here is my own memory optimisation tips for those who want to try it out.

1. Try to seprate out all the memory allocation operations in your application

2. Check before doing any memory operation for any hogged up memories in application

3. Always make variables null if they are not intended to be use, even if they are loal variables.

4. Before doing any major memory allocation work do call system.gc(). It seems idiotic but it surely helps.

5. Dont ever do memory operations in one big chunk. sub divide memory operations in to sub modules. It helps in cleaning memroy and allocationg memory for further modules.

6. Try to use minimum number of for loops they take more memory.

7. All systems prints should be commented out before production release, they also tend to increase memory.

8. For image resources make images as png 24 and keep color combn as low as possible.

9. While deleting recordstore if you are using connection database then dont run null query, simply nullify the recordstore.

So by doing all this i got what i wanted to do.

No comments:

follow me