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

后端 未结 7 2019
情书的邮戳
情书的邮戳 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:09

    Yes, it is possible if you reimplement GC in your applications. My answer is inspired by your discussion with Patricia, where you said you want to have all references to that object set to null. GC example:

    class MyGC {
       byte[100000] myMemory;
       int nextFreeCell;
       myNew (int value) { }
       get (int myCell) { }
    }
    

    This way you can control that there are no other refernces to your class. Your class must also contain the refernces to your GC memory only. Your example:

    int cell = MyGC.new(A.class)
    
    MyGC.get(cell).doSomething();
    
    if (MyGC.get(cell) == null)
       --- true -----
    

提交回复
热议问题