Home

metaspace

Metaspace is a memory area in the Java Virtual Machine used to store metadata for classes loaded by the application. It was introduced in Java 8 to replace the older PermGen space and, unlike the Java heap, resides in native memory (off-heap). This design allows metaspace to grow automatically based on the needs of the running application, constrained only by the host system memory unless a maximum size is configured.

What it stores and how it behaves

Metaspace holds the metadata the JVM needs to define and work with loaded classes, such as information

Configuration and limits

By default metaspace size is not fixed and can grow as needed. It can be bounded with

Troubleshooting and monitoring

Common symptoms include OutOfMemoryError: Metaspace after extensive dynamic class loading or redeployments. Solutions include increasing MaxMetaspaceSize,

about
class
definitions,
methods,
fields,
and
related
runtime
structures.
The
data
stored
here
is
created
as
classes
are
loaded
and
can
be
reclaimed
when
their
defining
class
loaders
become
eligible
for
garbage
collection.
This
means
that,
in
contrast
to
the
fixed
PermGen,
metaspace
size
can
expand
and
shrink
over
the
lifetime
of
an
application,
subject
to
memory
availability
and
any
configured
limits.
-XX:MaxMetaspaceSize
to
cap
native
memory
usage.
The
option
-XX:MetaspaceSize
sets
the
initial
size
at
which
the
JVM
may
trigger
a
growth
operation
and
GC.
Other
flags
control
how
aggressively
the
JVM
frees
unused
space.
If
metaspace
runs
out
of
memory,
the
JVM
may
throw
java.lang.OutOfMemoryError:
Metaspace.
ensuring
proper
unloading
of
classes
by
removing
references
to
obsolete
class
loaders,
reducing
dynamic
class
generation,
and
analyzing
classloading
leaks.
Metaspace
usage
can
be
monitored
with
tools
like
jcmd,
jstat,
VisualVM,
or
JVM
native
memory
profiling.