• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How is heap memory allocated?

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody?
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using WTK emulator, try this
Edit -> Preferences -> Monitor -> Enable Memory Monitor
I hope this helps..
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic