Java/Memory
From charlesreid1
Rules of Thumb
Memory usage and space in Java
Primitive types:
- 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)
Objects:
- 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:
- 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 %.
Flags
Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: