Young
Generation
Memory for
all the newly created objects is created in young generation. Young generation
is divided 3 spaces.
a.
Eden
Space
b.
Survivor
space1
c.
Survivor
space2
When the
application starts up, all the objects stored in Eden space. When the garbage
collection happens, then the objects that are survived from garbage collection
are moved to survivor space 1. At any point of time, only one survivor spaces
is in use. In further garbage collections, objects that are survived in both
eden space and survivor spaces are moved to second survivor space. This time
survivor space 2 is active and survivor space 1 is empty. In next garbage
collection cycles, live objects will be moved to survivor space1. This way, Objects
copied between survivor spaces.
Minor
Garbage Collection
When garbage collector collect objects from young generation, it is called as Minor
garbage collection. Minor garbage collection happen, when the young generation
is full.
Old
Generation
All the
long lived objects are stored in old generation of the heap. If an object survived
in young generation for more garbage collection cycles, then it is moved to old
generation.
S0 stands
for Survivor space 1
S1 stands
for Survivor space 2.
What is
Major garbage collection?
Major
garbage collection happen, when the old generation is full. Major garbage
collection happen less frequently as compared to minor garbage collection.
Major
garbage collection collect live objects from both young and old generations. This
is also called as full GC.
Permanent
Generation
Information
required by java run time (like metadata) is stored here. For example, all the
classes information is stored in permanent generation. Permgen is part of heap
space.
From java8
onwards, there is no perm gen, it is replaced with metaspace, which is not part
of heap. Metaspace is part of native memory, which is limited by host operating
system.
How to
set maximum metaspace for an application?
Use the
option -XX:MaxMetaspaceSize to set maximum metaspace.
No comments:
Post a Comment