Showing posts with label j2me. Show all posts
Showing posts with label j2me. Show all posts

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.

Wednesday, April 22, 2009

Blackberry lets me down one more time :(

After my push registry incidence with blackberry , i thought that was my last mishap with blackberry and there will not be anymore just wait and see scenerio .

Yet once again the demon of blackberry has haunted me. And this time it has outdone itself.

What i was trying was to see whether i can add localisation concept in my one of the small application.

I made a phrase book which has around 25 phrases in english and i was thinking of using localisation concept and translating these 25 phrases into all readily available languages.

For my first draft i target Hindi,Herbrew,Arabic and Albanian language.

Also as i was making this project in j2me i had no issue with porting it on blackberry. Polish was there for me.
Anyways when i started developing this one lame project( initially i thought it will be one day work) , i first tried to put the translations in a txt file , and then had a hearty laugh on myself. Text file wont understand a thing about hindi as that font is not readable by it.

So , i said to myself " no issue dex, lets try the unicode thing". That is make a file in unicode format and read it that way. So when i read that file in UTF 8 format the system does not try to apply its mind and render it the way it is.

Voila it worked on my symbian device( I have one N72 and nokia 5000).

So here i thought all done in one day i can simply make a build for blackberry and give it a look.

And then my whole world of programming got cursed.

None of my UTF file worked on blackberry. My code seem to read them properly but when i displayed the contents, it was showing everythin in blocks.

Initially my guess was that blackberry was having issue in reading UTF file, but when i digged internet a bit on this issue , i came to know it was not the UTF it was the RIM who was putting curses on me one after another.

The issue here was unavailbility of different languages font.

Even if we enter any text in UTF format, to display it the device needs to have that specific font.

I dont know how but the lowest device on nokia seems to be having all the fonts which i was targetting but Blackberry dint even have the basic fonts except the languages it said it supprted which were all english based.

So here again am doomed and am thinking what can i do. I looked for UTF renderer for blackberry but found nothing. I looked for font installer and found nothing.

Am still on it but am not hoping alot . May be blackberry should start thnking in global perspective if they are hoping and are actually trying to get their devices to the masses.

Lets see what happens.

follow me