Name

Leak Collection

Mistake

Objects with a short lifespan cannot be garbage-collected because an object with a long lifespan refers to them, resulting in a memory leak.

Watch for It When

Using objects with mismatched lifespans (usually collections), using objects that use collections internally, such as listeners, and using caches.

Solution

Put adds and removes close to each other in the code. If you have a cache, define an expiration policy. Where possible, use weak references to allow garbage collection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset