Home

MaxMetaspaceSize

MaxMetaspaceSize is a Java Virtual Machine (JVM) option that limits the maximum amount of native memory that may be used for metaspace, the area that stores class metadata. Introduced in Java 8 as a replacement for PermGen, metaspace memory is allocated from native memory and is separate from the Java heap. Metaspace grows as new classes are loaded and can shrink when classloaders are garbage collected and classes are unloaded.

If MaxMetaspaceSize is not set, metaspace can grow dynamically up to the limits of the process and

Two related options control metaspace behavior. -XX:MetaspaceSize specifies the initial threshold for metaspace; when usage exceeds

Practical tuning involves balancing memory footprint with class loading behavior. Metaspace usage can rise in environments

the
operating
system,
potentially
leading
to
OutOfMemoryError:
Metaspace
when
memory
is
exhausted.
Setting
MaxMetaspaceSize
provides
an
upper
bound
to
prevent
uncontrolled
growth,
which
can
be
important
in
long-running
applications
or
containerized
environments.
this
value,
the
JVM
triggers
a
garbage
collection
to
reclaim
unused
metaspace
before
allowing
further
growth.
-XX:MaxMetaspaceSize
sets
the
hard
ceiling
for
metaspace
growth;
attempting
to
allocate
beyond
this
limit
results
in
java.lang.OutOfMemoryError:
Metaspace.
Both
values
can
be
specified
with
units
such
as
k,
m,
or
g
(for
example,
-XX:MaxMetaspaceSize=1g).
with
many
dynamically
loaded
classes
or
frequent
redeployments.
Monitoring
metaspace
usage
helps
determine
appropriate
values,
especially
in
constrained
environments
like
containers.