5 questions to test your understanding
A Java method creates a Rectangle object, computes its area, and returns only the integer area. Escape analysis determines the Rectangle is non-escaping. Which optimization is the compiler most likely to apply?
An object is passed to a virtual method call on an interface type. Why does the compiler typically conservatively assume this object escapes?
Stack allocation is faster than heap allocation primarily because the stack resides in faster physical memory (L1 cache) while the heap uses slower main memory.
An object that is returned from a function always escapes that function's scope and therefore cannot be stack-allocated.
What does it mean for an object to 'escape' a function, and why must escape analysis be conservative when it cannot determine escape status?