Is it possible to set an Object to be null from within itself?

后端 未结 7 2023
情书的邮戳
情书的邮戳 2021-02-07 07:06

I know that this = null is illegal.

I\'m wondering if there\'s some other way to have an object clean itself up.

my desire is to be able to do some

7条回答
  •  借酒劲吻你
    2021-02-07 08:03

    That is not possible, I would think. If a is an instance variable of some object x, doStuffAndDisappear somehow could get a reference to x and call a setter to set a to null. Better not to go that route as it is totally counter intuitive.

    Best would be to clean up in doStuffAndDisappear (well, cant make is disappear) and make sure that no one else is referring is to a. GC should take care of rest.

提交回复
热议问题