字符串和垃圾收集 [英] Strings and Garbage Collection

查看:139
本文介绍了字符串和垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到相互矛盾的故事,关于这个话题,我期待为清楚一点。

I have heard conflicting stories on this topic and am looking for a little bit of clarity.

将如何处置一个字符串对象立即或在它最起码痕迹明显?

How would one dispose of a string object immediately, or at the very least clear traces of it?

推荐答案

这要看情况。文字字符串是拘留每默认,所以即使你的应用程序不再引用它它不会被收集,因为它是由内部实习结构引用。其他的字符串是就像任何其他管理对象。只要他们是由您的应用程序不再引用他们有资格进行垃圾回收。

That depends. Literal strings are interned per default, so even if you application no longer references it it will not be collected, as it is referenced by the internal interning structure. Other strings are just like any other managed object. As soon as they are no longer reference by your application they are eligible for garbage collection.

更多关于实习在这里这个问题:<一href="http://stackoverflow.com/questions/372547/where-do-java-and-net-string-literals-reside/372559#372559">http://stackoverflow.com/questions/372547/where-do-java-and-net-string-literals-reside/372559#372559

More about interning here in this question: http://stackoverflow.com/questions/372547/where-do-java-and-net-string-literals-reside/372559#372559

这篇关于字符串和垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆