作者在这个Item的最后一段很好总结了,关于垃圾最少化的技术。
摘如:
The Garbage Collector does an efficient job of managing the momory that your application uses.But remember that creating and destroying heap object still takes times.
- Avoid create excessive objects;don't create what you don't need
- Also avoid creating multiple objects of reference types in local functions.
- Instead consider promoting local variable to member variables, or create static objects of the most common instance of your types.
- Finally,consider creating mutable builder classes for immutable type.