你好: Joshua Bloch 说道“If a stack grows and then shrinks, the objects that were popped off the stack will not be garbage collected, even if the program using the stack has no more references to them.” 在此例中没有提供收缩stack 的方法,被抛出的对象用户依然能访问,对象处在reachable 状态,这时对象当然不能被gc。如果提供了stack 收缩,此时的已抛出对象仍然能被gc。
我觉得这个例子中的错误完全由程序员造成。我试过只要stack 收缩后,其pop的对象既被gc。
此为小弟一家之言。请大家发表意见指正。