I'm having trouble with excessive memory consumption in my J2ME program (so nothing new I guess) and here is the situation: seems like the more available memory a cellphone has the more memory program takes. Program alone is runnable quite fine with different memory configurations but when other programs are being loaded (like calendar) on top of the midlet it just quits without any prompt. So I guess its out of memory problem. I have inspected the available memory using 3rd party programs like TaskSpy. For example when Nokia E70 is being used my program takes a whopping 6 mb memory on load and another 6 mb on running. On Nokia 6630 it takes 2,5 mb on load and maybe some 1 mb on running. Netbeans memory profiler shows 500 kb spike on load and steady 300-400 kb consumption when running which seems much more reasonable figures considering the relative simplicity of the program. The program must be able to run in background and the user has to be able to use basic phone functions like calendar.
Does anyone have any idea what is the reason behind this "dynamic" memory consumption and how it could be mastered? Is it possible to e.g. restrict the KVM sandbox size to specific maximum limit? I doubt, but is it sensible to observe free memory with Runtime.freeMemory() and then use gc() when memory has dropped to specific level? Runtime.freeMemory() doesn't seem to give very reliable results and gc() is seemingly no magic word for memory related problems.
My program size is about 160 kb obfuscated. It has 20.000 LOC + 500 lines of localization data in 22 classes. Image/audio data is 40 kb. Maximum of 2 threads is run simultaneously. My recordstore contains data only a few thousand characters. I know the basic memory optimization tricks but I havent gone as far as memory pooling because I don't believe memory fragmentation is problem.