一个对象的存在,以及在这种情况下会发生什么 [英] existence of an object, and what will happen in this case

查看:111
本文介绍了一个对象的存在,以及在这种情况下会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个来自人的对象:

  Person p = new Person(andrea); 

如果现在创建P的另一个对象:

  p =新人(Sam); 

在Person Andrea中发生了什么?它会从垃圾收集器中删除?或者它仍然存在?如果是这样的话,我该如何删除Andrea的对象?



Thanx为您的解释提供帮助。

解决方案

是最初指向 Person andrea。创建新的 Person 并使 p 指向它后, Person 早先创建的对象(andrea)变得无法访问,因此有资格使用GC 。当实际对象将被GCed取决于当前的JVM状态和正在使用的GC。


let's say we have an Object from person:

Person p = new Person("andrea");

if I create now another object of P:

p = new Person("Sam");

what happen in this cas with Person Andrea? it will be removed from the Garbage Collector? or it will still be exists? if so how can i delete Object of Andrea?

Thanx for your Explanation an Help.

解决方案

p is a reference that initially points to Person "andrea". Once you create a new Person and make p point to it, the Person object created earlier ("andrea") becomes unreachable and hence eligible for GC. When the actual Object will be GCed depends on the current JVM state and the GC being used.

这篇关于一个对象的存在,以及在这种情况下会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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