# Class Unloading in Layered Java Applications

DevFeed: [Class Unloading in Layered Java Applications](<https://devfeed.tech/articles/class-unloading-in-layered-java-applications-18809.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/class-unloading-in-layered-java-applications/>)

Published: 2020-10-14T15:45:00Z

Content type: tutorial

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [JavaFX](<https://devfeed.tech/topics/javafx.md>), [Quarkus](<https://devfeed.tech/topics/quarkus.md>), [Spring Boot](<https://devfeed.tech/topics/spring-boot.md>)

Tags: [blog-post](<https://devfeed.tech/tags/blog-post.md>), [java](<https://devfeed.tech/tags/java.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [memory](<https://devfeed.tech/tags/memory.md>), [modules](<https://devfeed.tech/tags/modules.md>)

## AI overview

This article examines class unloading in layered Java applications. It explains how Java platform module system layers can support dynamic plug-ins, including plug-ins in JavaFX applications, and discusses how to ensure classes from removed plug-in layers are unloaded to prevent increasing memory consumption.

## Source excerpt

Table of Contents Do We Really Need Plug-ins? Plug-ins in Layered Java Applications Class Unloading in Practice If Things Go Wrong Learning More Layers are sort of the secret sauce of the Java platform module system (JPMS): by providing fine-grained control over how individual JPMS modules and their classes are loaded by the JVM, they enable advanced usages like loading multiple versions of a given module, or dynamically adding and removing modules at application runtime. The Layrry API and launcher provides a small plug-in API based on top of layers, which for instance can be used to dynamically add plug-ins contributing new views and widgets to a running JavaFX application. If such plug-in gets removed from the application again, all its classes need to be unloaded by the JVM, avoiding an ever-increasing memory consumption if for instance a plug-in gets updated multiple times. In this blog post I'm going to explore how to ensure classes from removed plug-in layers are unloaded in a timely manner, and how to find the culprit in case some class fails to be unloaded.