How it  works...

The first line of defense is the code itself. In the previous recipes, we have already discussed the need to release resources as soon as they are not needed anymore and the usage of StackWalker to consume less memory. There are plenty of recommendations on the internet, but they might not apply to your application. You'll have to monitor the memory consumption and test your design decisions, especially if your code handles a lot of data before deciding where to concentrate your attention. 

For example, the choice of the collection (different collections use more or less memory) may be irrelevant if your collection is going to be small. However, programmers usually use the same coding pattern, and one can identify the code's ...

Get Java 9 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.