F
F
FreeD12019-11-01 21:08:59
Java
FreeD1, 2019-11-01 21:08:59

How does the new operator work with memory in Java?

Ku geez.
There is a question here about how the new operator interacts with memory in general, how it calculates the required amount of memory and where is it stored? And does the variable created with new store a reference to a cell in memory where the class object itself is reserved? And are there any pitfalls with this operator?
I would be grateful for a detailed answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayton2019, 2019-11-02
@FreeD1

Memory is allocated in eden space according to the stack principle. Therefore, the allocation itself is fast. When eden overflows, the GC cleanup and compaction procedure starts. The physical addresses of objects may change in this case. After several cleanup phases, the surviving objects are moved to PermGen/Metaspace as permanent. This is how the lifecycle works for the classic gc. The new ones, I don't know. There may be nuances.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question