One of the popular Java interview questions is, can you enforce garbage collection? Java runtime memory management remains outside a programmer's control and sometimes acts as an unpredictable Joker it interrupts the otherwise well-performing application and initiates a stop-the-world full-memory scan. It typically happens at the worst possible time. It is especially annoying when you try to measure your application performance under the load using a short run and realize afterward that a lot of time and resources were spent on the garbage collection process and that the pattern of the garbage collection, after you changed the code, became different than before the code change.
In this chapter, we described quite a few programming tricks and solutions that help to ease pressure on the garbage collector. Yet, it remains...