JVM OutOfMemory — Meta Space

  1. Classloader leak — Thread Local variables
  2. Duplicate objects
  3. OSGI Class loader leak
  4. Metaspace size is less
Main.java--------------public class Main {public static void main(String...args) throws Exception {loadClass();while (true) {System.gc();Thread.sleep(1000);}}private static void loadClass() throws Exception {URL url = Main.class.getProtectionDomain().getCodeSource().getLocation();MyCustomClassLoader cl = new MyCustomClassLoader(url);Class<?> clazz = cl.loadClass("com.test.Foo");clazz.newInstance();cl = null;}}class MyCustomClassLoader extends URLClassLoader {public MyCustomClassLoader(URL... urls) {super(urls, null);}@Overrideprotected void finalize() {System.out.println("*** CustomClassLoader finalized!");}}Foo.java------------------------------public class Foo {private static final ThreadLocal<Bar> tl = new ThreadLocal<Bar>();public Foo() {Bar bar = new Bar();tl.set(bar);System.out.println("Test ClassLoader: " + this.getClass().getClassLoader());}@Overrideprotected void finalize() {System.out.println( this + " finalized!");}}Bar.java----------------------------------public class Bar {public Bar() {System.out.println(this + " created");System.out.println("Bar ClassLoader: " + this.getClass().getClassLoader());}@Overridepublic void finalize() {System.out.println(this + " finalized");}}
public class Foo {private static final ThreadLocal<String> tl = new ThreadLocal<String>();public Foo() {Bar bar = new Bar();tl.set("Hello");System.out.println("Test ClassLoader: " + this.getClass().getClassLoader());}@Overrideprotected void finalize() {System.out.println( this + " finalized!");}}
public static void main(String...args) throws Exception {//loadClass();new Thread(new FutureTask(() -> { loadClass(); return null; })).start();while (true) {System.gc();Thread.sleep(1000);}}




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Motivate Yourself to Be a Good Programmer

“When I started doing this, there were barely places to look for samples”: David González on…

How dApps Are Shaping The Future Of SaaS And Software Development

Understanding Python Data Model: A Simple Introduction

Ever since I was a little boy, I have only ever wanted to be a Doctor.

{UPDATE} Sea of Lies: Brennende Küsten - Wimmelbild, Rätsel, Puzzles und Abenteuer Hack Free…

My Splitting class's 'Thumb Rule'

Top Quotes from Cloud Foundry Summit North America 2020

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sumanta pakira

Sumanta pakira

More from Medium

[WSO2 APIM 4 Micro Integrator Profile] Updating the Key name in JSON payload

Controllability and Observability in Kalman’s test.

zio-test and diffx integration

Jayway Jsonpath can consume most of your service CPU, If you are using it in wrong way.