Rules of Thumb
Memory usage and space in Java
- boolean - 1 byte
- byte - 1 byte
- char - 2 bytes
- int - 4 bytes
- float - 4 bytes
- long - 8 bytes
- double - 8 bytes
An integer has 2^32 different values, with 32 bits or 4 bytes (since there are 8 bits per byte)
- Object overhead is 16 bytes of object overhead for each object
- References to objects typically use 8 bytes of memory.
- Data types can contain references to objects. The data type automatically incurs 16 bytes overhead for each object instance, plus 8 more bytes for each object's reference to another object.
- Arrays are implemented in Java as objects, with two instance variables - a pointer to the memory location of the first array element, and the length of the array.
- Primitive types - arrays use 24 bytes of header information, plus n times number of bytes to store each element
Example: int array
- int = 4 bytes
- int = 4n + 24 ~ 4n bytes
Example: double array 1D
- double = 8 bytes
- double = 8n + 24 ~ 8n bytes
- double = 8n^2 + 32n + 24 ~ 8n^2
Computing Max Memory
Max memory for a java application :
[-Xmx] + [-XX:MaxPermSize] + number_of_threads * [-Xss]
VM memory overhead is not a fixed %.
Computer Sciencenotes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Flags · Template:CSFlag · e