File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Out of Memory Error - optimisation tips? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Out of Memory Error - optimisation tips?" Watch "Out of Memory Error - optimisation tips?" New topic
Author

Out of Memory Error - optimisation tips?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
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
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
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.


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184
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
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
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
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
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Out of Memory Error - optimisation tips?
 
Similar Threads
Strings
Why are same stringbuffers not equal?
I think I have a memory leak: 33 megs of char arrays.. what to do?
Strings, StringBuffers and available memory
Question about Strings