• Post Reply Bookmark Topic Watch Topic
  • New Topic

instance self destroy  RSS feed

 
chihwah li
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello,

Is it possibe for an instance to de-reference (destroy) itself?

Cw
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chihwah li wrote:Is it possibe for an instance to de-reference (destroy) itself?

No. [Edit] At least not without some involved callback logic; which seems kind of pointless to me.

Winston
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a specific use-case? Perhaps a Soft, Weak, or PhantomRefence will do?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
chihwah li wrote:Is it possibe for an instance to de-reference (destroy) itself?

No. [Edit] At least not without some involved callback logic; which seems kind of pointless to me.


Agreed. Since an object doesn't know what references are pointing to it, it doesn't know if it is eligible for GC -- and regardless, even it it did, it can't dereference a variable that is out of its scope (and / or violate access modifiers).

But.... An object can still destroy its usefulness. The object can simply close connections, close files, cleanup and delete resources -- and when its methods get called, simply throw an exception.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!