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)

Preface

Understanding how Java memory works can be of great benefit to your Java coding and application management. It makes it easier to visualize what is going on with object composition and what happens with object allocation and deallocation, combined with object composition. As you are probably aware, object composition is where objects contain other objects. For example, a Person class specifies a property of type Address, which also happens to be a class. Knowing how this all works in memory makes it easier to know what steps to take to get to a certain data field.

Also, the concept of static and accessing the instance using the this keyword will be so much easier to visualize and understand completely when you understand how the memory of Java works. Without understanding how Java memory works, it is impossible to truly grasp the concepts of static and this.

Another advantage of understanding Java memory well is that the difference between using a primitive or a class reference as an argument makes a lot more sense all of a sudden. This also helps with understanding the immutability and mutability of objects.

More complex topics will make more sense too, such as concurrency, one of my personal favorites. This is when multiple things are happening at the same time in your application (multithreading). It’s possible that you haven’t worked with it yet, but as a Java developer, you’ll have to one day. Understanding Java memory makes it easier to understand certain aspects of concurrency, especially data access. Another complex topic that will be easier to understand is garbage collection. This is of crucial importance for performance since it’s a very expensive process, and you want to need it as little as possible and optimize it as much as possible.

Everything that you are probably using on a daily basis already will become clearer when you understand better how Java memory works.