1. An obsolete reference is simply a reference that will never be dereferenced again.
2. Memory leaks in garbage-collected languages (more properly known as unintentional object retentions) are insidious.
3. If an object reference is unintentionally retained, not only is that object excluded from garbage collection, but so too are any objects referenced by that object, and so on.
4. null out references once they become obsolete.
5. Nulling out object references should be the exception rather than the norm. The best way to eliminate an obsolete reference is to let the variable that contained the reference fall out of scope. This occurs naturally if you define each variable in the narrowest possible scope.
6. Whenever a class manages its own memory (i.e. object array), the programmer should be alert for memory leaks. Another common source of memory leaks is caches.
7. If you’re lucky enough to implement a cache for which an entry is relevant exactly so long as there are references to its key outside of the cache, represent the cache as a WeakHashMap; entries will be removed automatically after they become obsolete. Remember that WeakHashMap is useful only if the desired lifetime of cache entries is determined by external references to the key, not the value.
8. Under these circumstances, the cache should occasionally be cleansed of entries that have fallen into disuse. This can be done by a background thread (perhaps a Timer or ScheduledThreadPoolExecutor) or as a side effect of adding new entries to the cache. The LinkedHashMap class facilitates the latter approach with its removeEldestEntry method.
9. A third common source of memory leaks is listeners and other callbacks. If you implement an API where clients register callbacks but don’t deregister them explicitly, they will accumulate unless you take some action. The best way to ensure that callbacks are garbage collected promptly is to store only weak references to them, for instance, by storing them only as keys in a WeakHashMap.
10. For more sophisticated caches, you may need to use java.lang.ref directly.
相关推荐
Item 7: Eliminate obsolete object references Item 8: Avoid finalizers and cleaners Item 9: Prefer try-with-resources to try-finally 3 Methods Common to All Objects Item 10: Obey the general contract ...
This brief book explains the advantages of ...Chapter 6: More Ex Nihilo Objects Chapter 7: Inheritance Alternatives Chapter 8: Designing for JavaScript Chapter 9: On Constructors Chapter 10: Appendices
CEM v3.1 aims to: eliminate redundant evaluation activities; reduce/eliminate activities that contribute little to the final assurance of a product; clarify CEM terminology to reduce misunderstanding...
Rocksteady Overview: Eliminate Sync Replication Problem: Synchronous replication bottleneck at target Solution: Safely defer replication until after migration
6 Assume They’re All Out to Get You: Securing Your Application 295 7 Remember Me?: Building Personalized Web Apps 345 7 Sharing is Caring: Eliminate Duplicate Code 417 8 Harvesting Data: Control Your...
- NEW: Support for setting selectedIcon of list item in editor. - IMPROVED: Add UIConfig.depthSupportForPaitingMode. - IMPROVED: Set sorting order of popup automatically. - FIXED: Fixed a text layout ...
资源分类:Python库 所属语言:Python 资源全名:eliminate-newlines-1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
This brief book explains the advantages of the object model, inheritance, both classical and prototypical, and shows how these concepts can be implemented in JavaScript. It also shows how object ...
Debug Version: 154.6K Code, 63.0K Data, 217.6K Total Current Release: Non-Debug Version: 78.1K Code, 17.1K Data, 95.2K Total Debug Version: 155.4K Code, 63.1K Data, 218.5K Total 2) iASL Compiler/...
Deliver Professional Applications: Eliminate embarrassing typos from your applications (Windows and Web Forms, UI controls, ToolTips, message boxes, and more). Improve the Quality of Your ...
Eliminate 消除类游戏(cocos2d-x实现) 详细介绍
Deliver Professional Applications: Eliminate embarrassing typos from your applications (Windows and Web Forms, UI controls, ToolTips, message boxes, and more). Improve the Quality of Your ...
A new algorithm to eliminate the ambiguity of GPS
Optical_IO_Chiplets_Eliminate_Bottlenecks_to_Unleash
A lot of change introduced in Java EE 6 as below: New model:Annotation-based programming model Light weight:Reduce or eliminate need for DD Others:Traditional API for advanced users etc...
Chapter 6: User Input: Getting Data in Runtime Chapter 7: The String Object Chapter 8: Boolean Logic Chapter 9: Loops and Arrays Chapter 10: Methods Chapter 11: Inheritance and Polymorphism Chapter 12...
介绍通过arcgis软件消除大的碎图斑,现在借助 ArcGIS的Eliminate工具可以很轻松的完成这个工作。该工具可以将选中的多边形合并到周围边大的多边形当中去。
《星际争霸2》 ...Victory Condition : Eliminate the enemy Time Limit : 1 min 30 sec Modified from PySC2 mini games ( DefeatRoaches ) 运行: ~\DQN python3 main.py ,不带任何命令行参数 总体表现令
信息安全_数据安全_How_to_Eliminate_a_Major_Vulnera 隐私合规 边界防御 安全防护 web安全 工业网络
简单的小游戏 点击里面的index.html