Well, it's not so clear cut with the new VMs. It will even put entire object into a register if it can.
class Thing { short a; short b; } You have the normal thread stack space which it uses when it detects locality of reference. Then you have the eden space which is a stack associated with a thread. Once this fills up it scans it for any surviving objects and copies them to the first level 'heap' space. Which is a stack itself. eg. A whole bunch of StringBuilder concats would all push onto this stack. The final toString() result would survive. I think there is a secondary space for objects which survive for a long long time. But collection isn't run as often here. On Jul 22, 9:03 am, Alexey Zinger <inline_f...@yahoo.com> wrote: > I was under the impression that primitives are heap managed when they're > inside an object: > public class Foo { public int bar; } > > And of course they're stack managed otherwise: > public void func(int foo) { int bar; } > > Alexey > 2001 Honda CBR600F4i (CCS) > 1992 Kawasaki > EX500http://azinger.blogspot.comhttp://bsheet.sourceforge.nethttp://wcollage.sourceforge.net > > ________________________________ > From: pramod nepal <neppra...@gmail.com> > To: javaposse@googlegroups.com > Sent: Monday, July 20, 2009 1:08:26 PM > Subject: [The Java Posse] Re: Heap and Stack memory > > Stack and heap are both memories of RAM. Stack is a common place for > most of memory storage. Both of these allocated memory inside jvm. > Heap is a dedicated memory storage created only when we initialize > using the new operator. They are easily freed or garbage collected > when no more required. Objects created from classes are stored in > heap. Eg int is stack managed and Integer is heap managed. Storage > algorithm is different. Stack initialized may not properly manage > contigious memory and may waste memory. Each heap initalized gets > contigious memory. After object is freed memory re-organizes to claim > original space and re constructs to leave no free space betwn two > managed objects --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javaposse@googlegroups.com To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---