2 ms·
> If you're talking about stack allocation, memory usage will be the same The JVM never literally 'stack allocates'. It scalar replaces objects, so object head
by chrisseaton 8y ago
> If you're talking about stack allocation, memory usage will be the same
The JVM never literally 'stack allocates'. It scalar replaces objects, so object header words, klass pointers, unused fields disappear, and remaining fields become just dataflow edges so may be folded, or may end up in registers or on the stack. Additionally, objects which are 'stack allocated' do not need to be aligned as on the heap, and do not use GC head-room. All of this does mean a real reduction in memory consumption, but it's likely extremely small in practice.