3 ms·
It's problem of Java, because it uses heap objects for almost anything instead of using structs.
by vbezhenar 8y ago
It's problem of Java, because it uses heap objects for almost anything instead of using structs.
- pjmlp 8y agoIn Java a new doesn't always map to heap objects. Depends on which JVM one is talking about and what JIT is being used.
- vbezhenar 8y agoIf you're talking about stack allocation, memory usage will be the same. Stack allocation reduces GC pressure just a little bit, but if your software uses 25G RAM, it won't help. There's no JVM optimization that I'm aware of, to inline object inside another object.
- 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.
- chrisseaton 8y agoThe 'heap' in Java is an abstract concept. The JVM doesn't literally need to use heap objects for everything.