How to destroy object in itself

前端 未结 4 775
再見小時候
再見小時候 2021-02-18 18:05

Is there any solution for destroying current instance of object in itself ?

I am looking for something which looks like:

class KillMe {
    ....
    pub         


        
4条回答
  •  借酒劲吻你
    2021-02-18 18:58

    The object doesn't have access to the references to it so there's no way to set them to null or something else. An object can only be "destroyed" when the garbage collector comes around and clears out all unreferenced objects.

    That being said, try this:

    public void destroy() {
        System.exit( 0 );
    }
    

提交回复
热议问题