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 How is heap memory allocated? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "How is heap memory allocated?" Watch "How is heap memory allocated?" New topic
Author

How is heap memory allocated?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hello,
Can anyone tell me (or point me to a url) how heap memory is allocated when a midlet starts up?
I have a midlet that now gives an out of memory error whilst it is starting up. It seemed to be (tho this may be where my poor knowledge of the JVM/whatever is letting me down) that the error is thrown whilst it going through the (many) instance variables. I think this because the first lines of my constructor and startApp() methods are System.err.println's - and no such output is ever made to the output screen - so I concluded that the constructor and startApp() were never reached, so it must be the declaration of my instance variables that was gobbling up all the memory (only a few of my instance variables are initialised at the point of declaration).
So I created a test midlet that contained the same instance variables, an empty constructor, and the only methods being an empty startApp(), pauseApp() and destroyApp(). I expected that if I ran this it would give me the same out of memory error - but the result was that it ran fine with bags of free memory...
...which proves I have no idea of what's going on!
Can anyone help me out?!
Cheers,
James
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Anybody?


[Jess in Action][AskingGoodQuestions]
Jason Fox
Ranch Hand

Joined: Jan 22, 2004
Posts: 114
Wel, first of all, are you running on an actual device or an emulator? In an actual device, the typical printstreams (System.err.println, for example) are not handled by the screen. Unless you are debugging the app through a terminal (something I personally have never done) you will not see anything. To print information to the screen, use Displayable . append(String). To my understanding, (though I could easily be incorrect) actual implementation of how heap memory is allocated is left up to each device manufacturer/ implementor. If you post your code, I'll look at it and see if I can help.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya Jason,
I am running the midlet on an emulator. I actually get the out of memory error on sun one studio, but not on jbuilder (using the same emulator, nokia 3510i, with 200kB heap). I also the get out of memory error on real 3510i device.
Following my previous post, I also imagine/guess that the methods I have in my midlet are also allocated heap memory at startup... Am I right? If so, does anyone know how much memory is allovcated for a method? I mean, suppose a method returns a String[]; would this method be allocated the same amount of heap memory at startup as a String[] instance variable - or do the local variables within the method also have heap memory allocated?!
Thanks,
James
Jason Fox
Ranch Hand

Joined: Jan 22, 2004
Posts: 114
I'm not sure exactly why you would be getting that error only on Sun ONE Studio. Are there any SOS users out there that could explain this? Perhaps there is a way to set the memory in the emulator?
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Yes, the memory can be set, and I've kept it at the 200kB default (to resemble the real device).
My main question tho is how is heap memory initially allocated when the midlet starts up... How much heap memory (if any) do the methods occupy - would a method that, say, returns a String[] occupy the same amount of heap memory as a String[] instance variable??
Cheers,
James
Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
If you are using WTK emulator, try this
Edit -> Preferences -> Monitor -> Enable Memory Monitor
I hope this helps..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How is heap memory allocated?