Java Reference
In-Depth Information
concurrent GC cycles) will be reduced. And if those full GC cycles can clear up more
memory, then they will also occur less frequently.
This section investigates three ways to use less memory: reducing object size, lazy initializa-
tion of objects, and using canonical objects.
Reducing Object Size
Objects occupy a certain amount of heap memory, so the simplest way to use less memory is
to make objects smaller. Given the memory constraints on the machine running your pro-
gram, it may not be possible to increase the heap size by 10%, but a 20% reduction of half
the objects in the heap can achieve the same goal.
The size of an object can be decreased by (obviously) reducing the number of instance vari-
ables it holds and (less obviously) by reducing the size of those variables. Table 7-1 gives the
size of an instance variable of all Java types.
Table 7-1. Size of Java instance variables
Type
Size
1
byte
2
char
2
short
4
int
4
float
8
long
8
double
4 on 32-bit JVMs and 64-bit JVMs with
heaps of less than 32 GB; 8 on 64-bit JVMs
with large heaps [ a ]
reference
[ a ] See Compressed oops for more details.
 
 
Search WWH ::




Custom Search