Java Memory Management
4.5 (392 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
2,248 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Java Memory Management to your Wishlist.

Add to Wishlist

Java Memory Management

What Java professionals need to know about memory, garbage collection, tuning the VM, and avoiding memory leaks.
4.5 (392 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
2,248 students enrolled
Created by Matt Greencroft
Last updated 1/2017
Curiosity Sale
Current price: $10 Original price: $200 Discount: 95% off
30-Day Money-Back Guarantee
  • 3 hours on-demand video
  • 8 Supplemental Resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • The best Java programmers have a deep understanding of how memory works in Java, and use this to influence how they create their code. This course will give you that understanding, together with the tools that you will need to investigate when things go wrong.
  • By the end of this course, you'll understand important concepts like the stack and the heap, limitations of the final keyword, and how garbage collection works.
View Curriculum
  • This course is aimed at students with some basic knowlege of Java. If you are comfortable with creating basic applications, creating objects and running code, then you'll be fine to do this course. You will need to have a java compiler installed, and ideally a development environment such as Eclipse.

This is a course for Java professionals (or aspiring Java professionals) who need an in depth understanding of how memory works in Java. In this course you'll learn what kinds of memory leaks are possible in Java, and how to avoid them. In addition I'll show you tools you can use to analyse how your applications are performing, and detect inefficient memory use, such as objects which are taking up too much memory, or problems causing inefficient garbage collection. And we'll see how to fix these.

You don't need to be a Java Expert to do this course, but you should be able to confidently create basic Java code before you start.

Who is the target audience?
  • This is an advanced Java course, and is most suitable for Java programmers who have some experience creating real world production software.
  • If you have ever created code that has run out of memory, or suffered from poor performance due to memory usage, then this course will show you how to identify the cause and resolve the problem.
Students Who Viewed This Course Also Viewed
Curriculum For This Course
29 Lectures
Why memory is important
1 Lecture 01:45

An introduction to the course

Preview 01:45
How memory works in Java
3 Lectures 15:51

An introduction to how memory works in Java - outlining what we'll be studying in this section.

Preview 01:03

Java's memory management is based on two important concepts - the stack and the heap. In this chapter we learn what the stack is, and we see how variables are added to and removed from the stack during the execution of a Java program.

Preview 05:13

Java uses the heap to store objects. In this chapter we learn about how the heap and the stack work together to allow data to be passed between methods.

Introducing the Heap
Values and References
4 Lectures 23:44

In Java variables are always passed between objects by value - we understand what this means, and compare it to the "by reference" alternative that some languages offer.

Passing variables by value

Many programmers think that objects are passed by reference in Java - this isn't the case however, so we learn in this chapter how it does work, and why it's significant.

How objects are passed

In this chapter we understand why the final keyword cannot be relied on to make an object immutable (that it cannot change its state).  We'll see why there's no "const correctness" in Java.

The "final" keyword

This video, together with the code files that go with it, form a challenge for you to think about - you need to predict what will happen if you run the sample code, using what we've learned so far to work out the outcome.

Memory exercise
Escaping References
3 Lectures 34:52

We understand what escaping references are, why they are dangerous, and start to look at one way to avoid them when you need to pass collections between methods.

What are excaping references?

In this video we continue learning how to avoid escaping references - this time we look at custom objects.

Avoiding Escaping References

First we discuss why immutable objects are safe in Java, and then there's an exercise for you to try - to detect and remove escaping references in some sample code. 

Escaping References Exercise
Introduction to Garbage Collection
4 Lectures 39:21

Before we get into the detail of garbage collection, this chapter focuses on how Java can be efficient when you are creating strings, by placing them in a pool. 

String Pools

Garbage Collection is one of the ways that memory leaks become pretty impossible in Java. We start by understanding how the virtual machine decides which objects are eligible for garbage collection.

Preview 05:47

Java gives us the gc() method that we can use to try and influence a garbage collection to take place. We can use the finalise() method to find out if it did.

The gc() and finalise() methods

In this chapter we'll explore the closest thing to a memory leak that you can have in Java, which I refer to as a soft leak. I'll show you how to detect whether these are happening in your applications using the VisualVM tool. 

Detecting soft leaks
Generational Garbage Collection
5 Lectures 23:44

We'll learn more about how the garbage collection process works, using a system called mark and sweep.

Mark and Sweep

The JVM makes the mark and sweep process very efficient by using generations for the objects. We'll see this in practice using the VisualVM tool.

Generational Garbage Collection

We'll use what we've learned so far to visualise the soft leak we saw earlier, and understand the impact it has on the garbage collection process.

Using Visual GC to view a soft leak

In this chapter we use a further tool to help us identify the source of a memory leak - Eclipse's Memory Analyzer Tool

Using the Memory Analyzer tool

To finish this section, we'll talk about a special part of the heap called Permgen, and why in Java 8, you should no longer see any errors indicating that the Permgen space is full.

Permgen and Metaspace
'Tuning the Virtual Machine
5 Lectures 25:34

We start by seeing how to specify the heap size that we want our applications to be able to use

Heap Size

If you're using Java 7 or below, you may wish to set the permgen size. We'll see how to do that in this video.

Permgen Size

Next we see how to log when garbage collections take place, and we can specify the size of the young generation.

Garbage Collection and Generation sizes

If you have an application which is crashing in production systems with an out of memory error, this option will help you to investigate.

Generating Heap Dumps

Java gives us a choice of garbage collector, which can be used to improve performance depending on your hardware. We'll learn how to choose a collector, and how to find out which is the default for your computer.

Choosing a garbage collector
Hunting for a real world memory leak
3 Lectures 24:09

We'll be looking for a memory leak in a real world application - a Java website. In this video we'll install the website and see it running.

Introducing the application

We use the Visual VM tool to montior the application's memory usage, and the Apache j-meter tool to simulate production use.

Monitoring the application

We finally analyse the heap dump to work out where our memory leak is happening, and then fix and re-test.

Fixing a memory leak
Bonus section - weak and soft references
1 Lecture 04:09

This is a bonus chapter, covering weak and soft references, and the useful WeakHashMap object.

Weak and soft references
About the Instructor
Matt Greencroft
4.5 Average rating
389 Reviews
2,248 Students
1 Course
Course tutor at Virtual Pair Programmers

Having worked for over 20 years as a professional programmer, mainly in banking, Matt now teaches for Virtual Pair Programmers. His specialist areas are JavaEE, Android, Hadoop and NoSQL. Matt's currently working on a Clojure project, which he finds an enjoyable challenge!

Outside of work, Matt enjoys cycling, but prefers going downhill to uphill, and he also plays the piano… very badly.