Book Image

Java Memory Management

By : Maaike van Putten, Dr. Seán Kennedy
Book Image

Java Memory Management

By: Maaike van Putten, Dr. Seán Kennedy

Overview of this book

Understanding how Java organizes memory is important for every Java professional, but this particular topic is a common knowledge gap for many software professionals. Having in-depth knowledge of memory functioning and management is incredibly useful in writing and analyzing code, as well as debugging memory problems. In fact, it can be just the knowledge you need to level up your skills and career. In this book, you’ll start by working through the basics of Java memory. After that, you’ll dive into the different segments individually. You’ll explore the stack, the heap, and the Metaspace. Next, you’ll be ready to delve into JVM standard garbage collectors. The book will also show you how to tune, monitor and profile JVM memory management. Later chapters will guide you on how to avoid and spot memory leaks. By the end of this book, you’ll have understood how Java manages memory and how to customize it for the benefit of your applications.
Table of Contents (10 chapters)

Exploring the Metaspace

The Metaspace is the memory space that holds the class metadata that is necessary for runtime. It is the method area in the JVM specification and in most popular Java implementations after Java SE 7, this area is called the Metaspace.

If you know about PermGen, or you come across it, just know that this is the old memory area where all class metadata was stored. It had some limitations and has been replaced by the Metaspace.

So, back to this class metadata. What even is that? Class metadata is the runtime representation of the Java classes that are necessary to run the program. It actually contains a lot of things, such as the following:

  • The Klass structure (we’ll see more in Chapter 5 when we take a deep dive into the Metaspace!)
  • Bytecode of methods
  • The constant pool
  • Annotations and more

That’s it! These are the basics of Java memory management. There is a lot more to say about the specific parts. We are going...