Zooming in on the Heap Space
In Chapter 2, we discussed the differences between references and objects in memory. References and the objects to which they refer are closely related. We discovered that Java’s call-by-value mechanism could lead to a security issue known as escaping references, in addition to mutable objects. With the aid of sample code and diagrams, we examined the issues and how to resolve them using defensive copying.
We know that primitives and references can live on both the stack and the heap, whereas objects just live on the heap. Now, we are ready to take a closer look at the heap in preparation for the next chapter, which is on garbage collection (GC). In this chapter, we are going to cover the following topics:
- Exploring the different generations on the heap
- Learning how the spaces are used