When writing code, a programmer has two main objectives in mind:
- To implement the required functionality
- To write code that is easy to read and understand
Yet, while doing that, they also have to make many other decisions, one of them being which of the standard library classes and methods with similar functionality to use. In this recipe, we will walk you through a few considerations that help to avoid the wasting of memory and make your code style memory-aware:
- Pay attention to the object created inside the loop
- Use lazy initialization and create an object just before the usage, especially if there is a good chance that, this need may never materialize at all
- Don't forget to clean the cache and remove unnecessary entries
- Use StringBuilder instead of the + operator
- Use ArrayList if it fits your needs, before using HashSet (the memory...