How much memory space a Java object occupies

Source: Internet
Author: User

Recently in Flex, you need to encapsulate an event sheet Pojo object for presentation. Think of more than 6,000 records in the database, the encapsulation is sure to occupy a lot of memory, and the Flex object is completely passed from the Java object to encapsulate again, that is, twice times the amount of memory. So with the title in mind, how much memory does a Java Pojo object actually occupy?
As shown in the following question:
Object O=new Object ():
In Java, a hollow object occupies eight bytes, and the object's reference is four bytes. So the above statement occupies a space of 4byte+8byte=12byte.java memory is allocated in multiples of 8, so the allocated memory is 16byte.
As an example:
Class o{
int i;
BYTE J;
String s;
}
The size of the memory it occupies is empty object (8) +int (4) +byte (1) +string Reference (4) =17byte, because if 8 is an integer multiple, it occupies a size of 24byte.
Of course, if there are other objects in the class, it is also necessary to calculate the space of other objects, other object algorithms, as shown in the above object.

How much memory space a Java object occupies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.