当前位置: 技术问答>java相关
垃圾收集
来源: 互联网 发布时间:2015-07-18
本文导语: 我们知道,当一个对象没有引用时,JVM将在某一时刻进行垃圾收集。但是,对于互相引用的对象JVM是如何进行垃圾收集的?比如:对象a引用对象b,对象b引用对象a,但没有其他对象引用a,b。 | "...
我们知道,当一个对象没有引用时,JVM将在某一时刻进行垃圾收集。但是,对于互相引用的对象JVM是如何进行垃圾收集的?比如:对象a引用对象b,对象b引用对象a,但没有其他对象引用a,b。
|
"当一个对象没有引用时"
Not exactly.
it is 当一个对象is unreachable from any stack of the threads.
see:
http://www.csdn.net/expert/topic/872/872622.xml?temp=.2360041
Not exactly.
it is 当一个对象is unreachable from any stack of the threads.
see:
http://www.csdn.net/expert/topic/872/872622.xml?temp=.2360041
|
http://www-900.ibm.com/developerWorks/cn/java/j-jtctips/part2/index.shtml#to上面看看
|
你去ibm的开发站点找一下,哪里有一篇讲垃圾收集机制的文章。
不过对于你的问题,还是很容易想到解决的办法的,引用计数就可以。
不过对于你的问题,还是很容易想到解决的办法的,引用计数就可以。
|
不管几个对象互相引用,只要其不能被ROOT集的对象引用,那么它们都是GC的收集对象.
|
对象a引用对象b,对象b引用对象a?
怎么引用?用代码举个例子。
怎么引用?用代码举个例子。
|
there're variants in the algorithm that does the thing incrementally or generationally. So the deep copy is not done all at once.
ref-counting suffers from cyclic reference. And it also at least doubles the cost of reference assignment and destruction. think how frequent reference assignment and destruction can be in our program!
I believe that static singleton is per VM. But, you can make object-level singleton, which can be per container or per anything.
Don't spend too much time on pattern's concept. It's just a natural result of thinking, and some good practice. I wouldn't think it's a shame if I don't know a pattern's name or meaning. Say, "so what?"
ref-counting suffers from cyclic reference. And it also at least doubles the cost of reference assignment and destruction. think how frequent reference assignment and destruction can be in our program!
I believe that static singleton is per VM. But, you can make object-level singleton, which can be per container or per anything.
Don't spend too much time on pattern's concept. It's just a natural result of thinking, and some good practice. I wouldn't think it's a shame if I don't know a pattern's name or meaning. Say, "so what?"