Home> Java> javaTutorial> body text

What are the memory types allocated to objects in Java?

WBOY
Release: 2023-04-20 17:52:08
forward
949 people have browsed it

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(); } }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!