I don't think so. new Bar[500] will alocate an array of references. Each
bars[i] = new Bar() will allocate a Bar so you'll end with an array of 400
references and 5 Bar allocated.
>>I'm a little new here, so please bear with me if this sounds like a
>>goofy
[quoted text clipped - 16 lines]
> bars[i] = new Bar() will allocate a Bar so you'll end with an array of 400
> references and 5 Bar allocated.
Incorrect.
Bar bar[500]; allocates 500 references on the stack - no big space
requirement ... but each new Bar() will allocate a Bar object on the heap and
the space requirement for a Bar instance.

Signature
It's not the inital skirt length, it's the upcreep.
Frank van Schie - 26 Jun 2006 18:50 GMT
> > I don't think so. new Bar[500] will alocate an array of references. Each
> > bars[i] = new Bar() will allocate a Bar so you'll end with an array
[quoted text clipped - 6 lines]
> requirement ... but each new Bar() will allocate a Bar object on the
> heap and the space requirement for a Bar instance.
That's... what he said, barring syntax errors. Except he doesn't know
the difference between 400 and 500.

Signature
Frank
Mark Space - 26 Jun 2006 23:07 GMT
>> Incorrect.
>> Bar bar[500]; allocates 500 references on the stack - no big space
[quoted text clipped - 3 lines]
> That's... what he said, barring syntax errors. Except he doesn't know
> the difference between 400 and 500.
Probably a typo. The 4 and the 5 key are right next to each other.
Don't forget that a reference is NOT free. I think we already figured
out here on this list that most JVMs implement a reference as 8 bytes.
So Bar bar[500]; with no objects at all is still 4008 bytes for most JVMs.
My suggestion: use a collection.
dsjoblom@abo.fi - 28 Jun 2006 15:31 GMT
> Incorrect.
> Bar bar[500]; allocates 500 references on the stack - no big space
> requirement ... but each new Bar() will allocate a Bar object on the heap and
> the space requirement for a Bar instance.
Not correct about the stack allocation part. There is no way of knowing
where the Bar array (the piece of memory having space for 500
references) is allocated, unless you know the internal operations of
your JVM, but that is not portable information. Most *likely* it is
allocated on the heap as any other object. Typically, only local
primitives and references are allocated on the stack.
Regards,
Daniel Sjöblom