How do you write a deconstructor in Java?

后端 未结 7 2102
萌比男神i
萌比男神i 2020-12-20 08:17

I came across this question and am looking for some ideas?

7条回答
  •  死守一世寂寞
    2020-12-20 08:45

    Since others are talking about normal cases.. There are special cases where you want to create destroy(), destruct(), releaseExternalResources(), shutdown() etc. methods that should be actively called by the entity that controls the life cycle of that instance.

    For example, an object can be an ActiveObject, which has live threads in it. In this case, you want to shut them down because else you will have memory leaks.

    While one may not call that a destructor...

    On a sidenote, I guess that interview question was intended as a trick question!

提交回复
热议问题