Out of Memory Error - optimisation tips?

I am developing a midlet which used to run fine, but since I gave it a few more String's and String[]'s (and String[][]'s!) it now gives an Out of Memory error (which is thrown before the constructor or startApp() method is reached). I have changed a lot of the Strings to StringBuffers, and a lot of the arrays to comma-delimited Strings/StringBuffers, but still get the Out of Memory error. I was just wanting to know if anyone had any more tips to optimise my code in terms of heap memory, Strings and StringBuffers. (According to the Wireless Toolkit's Memory Monitor Extension, I have 90kB of char[], 20kB of byte[], 7kB of String, 7kB of 'VM Internal' and 6kB of StringBuffer. Any help much appreciated. Cheers, James

You can try to cache some heap memory data in to RMS and read them in as needed. Some devices have separate heap and RMS storage space. So, this might work. But it is a huge pain and takes a lot very specific optimizations.

Good question. Me too I had this problem. I could improve it a little. Don't use neither String or StringBuffer. I advice to use ByteArrayOutputStream. All data are in bytes. Michael: I am very intereted by your solution consisting to use RMS.Could you give me more explanation or example. Think you very much. OULD NADIF

We are ones that build the world, thus build it well.

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401

posted May 05, 2004 06:14:00

0

Thanks guys, Ould, if I used ByteArrayOutputStreams, do you know where I should expect to see the benefit?... i.e., would it take away a lot of the 90kB of char[] that I mentioned previously - that is, without adding to the 20kB of byte[] ?? Cheers, James [ May 05, 2004: Message edited by: James Hodgkiss ]

Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184

posted May 05, 2004 07:05:00

0

Hi, 1-To be honest, I don't never ask me myself this question. I have not knew if there are space allocated specially for the chars or bytes etc... On the other hand I know the memory allocated for a char is different for a String etc... Thus, I can't reply your request. 2-The benefit to use ByteArrayOutputStreams are: the concatenation of deux strings(+ or append )take more memory than to fill a buffer of byte. 3-A question for you: Do you know a way to reduce the memory used for the Canvas. Thanks OULD

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401

posted May 05, 2004 08:09:00

0

Ould, I have had a look at ByteArrayOutputStreams and I think that, for my purposes, they will *add* to the memory problem as I have to do a lot of string manipulation so will be converting it to a String a lot of the time.

Sorry, I don't know much about Canvases... Thanks again, James

Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184

posted May 06, 2004 02:11:00

0

Hi, Thanks for your reply. My way is that I always avoid to use any object each time that it is possible. I prefer use a Buffer. Sometimes I understand the use of String is compliant. Did you compare the two ways(String et ByteArrayOutputStream) on the memory and the speed? About to win some memory and speed I am always open to receice advice. Thanks a lot

OULD

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com