1. Two types
(1) Pointer collision allocation method is used to allocate objects in a neat pile of memory. All used memory is put aside, without The used part is on the other side, and a pointer is placed in the middle as an indicator of the boundary point. When allocating memory as an object, just move the pointer to an unused part and a distance equal to the object.
(2) The free list is suitable for allocating memory in irregular memory. In order to know which memory area is available, the virtual machine must maintain a list. When allocating memory, select a large enough space in the list to allocate to other side.
2. Application scenarios
The specific method used depends on whether the accumulated memory is neat and tidy, and whether the accumulated memory is neat and tidy depends on whether the garbage collector has a compression and sorting function.
3. Example
public class TestPerson { public static void main(String[] args) { Person = p1 = Person(); Person = p2 = Person(); p1.age = - 30; p1.shout(); p2.shout(); } }
The above is the detailed content of What are the memory types allocated to objects in Java?. For more information, please follow other related articles on the PHP Chinese website!