java – 你有没有在任何项目中使用过PhantomReference?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 你有没有在任何项目中使用过PhantomReference?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1313字,纯文字阅读大概需要2分钟。
内容图文
![java – 你有没有在任何项目中使用过PhantomReference?](/upload/InfoBanner/zyjiaocheng/713/cfd0c72887cc428f97b761596062581f.jpg)
我对PhantomReference唯一了解的是,
>如果使用其get()方法,它将始终返回null而不是对象.有什么用?
>通过使用PhantomReference,可以确保无法从finalize方法中复活对象.
But what is the use of this concept/class?
Have you ever used this in any of your project or do you have any example where we should use this?
解决方法:
我在simplistic, very specialized kind of memory profiler中使用了PhantomReferences来监视对象的创建和销毁.我需要他们来追踪破坏.但这种方法已经过时了. (它是在2004年针对J2SE 1.4编写的.)专业的分析工具功能更强大,更可靠,JMX或代理和JVMTI等新的Java 5功能也可用于此.
PhantomReferences(总是与Reference队列一起使用)优于finalize,它有一些问题,因此应该避免.主要是使对象再次可达.这可以通过终结者监护人习语来避免( – >在’有效Java’中阅读更多内容).所以他们也是新的定型.
此外,PhantomReferences
allow you to determine exactly when an object was removed from memory. They
are in fact the only way to determine that. This isn’t generally that
useful, but might come in handy in certain very specific circumstances
like manipulating large images: if you know for sure that an image should be
garbage collected, you can wait until it actually is before attempting to
load the next image, and therefore make the dreaded OutOfMemoryError less
likely. (Quoted from 07001.)
正如psd首先写的那样,Roedy Green有一个good summary of references.
内容总结
以上是互联网集市为您收集整理的java – 你有没有在任何项目中使用过PhantomReference?全部内容,希望文章能够帮你解决java – 你有没有在任何项目中使用过PhantomReference?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。