Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrichmon

macrumors 6502a
Jun 17, 2003
873
3
devman said:
If you were starting fresh and it was to be a GC environment what would you call the plugin point for people to "do whatever they have to do" before an object is GCed? dealloc is hardly a good name for this.

What you are describing is commonly called "finalizing" an object. GC semantics will guarantee that the GC calls that the appropriate finalization routine before the GC deallocates the object. In Java the finalization method is finalize(). Technically in a GC-based system the programmer should not be explicitly dealloc'ing any object -- I guess this is the point of your question.

Java's finalize() method is implemented in java.lang.Object and is over-ridden by developers who need to perform finalization activity. When implementing your own finalize() method it is vital that the method does not result in the allocation of any new objects. For example no String contatenation, otherwise you can end up in some nasty race conditions.
 

devman

macrumors 65816
Apr 19, 2004
1,242
8
AU
mrichmon said:
What you are describing is commonly called "finalizing" an object. GC semantics will guarantee that the GC calls that the appropriate finalization routine before the GC deallocates the object. In Java the finalization method is finalize(). Technically in a GC-based system the programmer should not be explicitly dealloc'ing any object -- I guess this is the point of your question.

Java's finalize() method is implemented in java.lang.Object and is over-ridden by developers who need to perform finalization activity. When implementing your own finalize() method it is vital that the method does not result in the allocation of any new objects. For example no String contatenation, otherwise you can end up in some nasty race conditions.

uh, you're talking to the wrong person. catfishman asked the question. You're making the same point I am (with more detail) and that is that in a GC environment a programmer isn't going to be dealloc'ing and hence dealloc is a bad name for the plugin point for finalization activities. Read the last 4 or 5 replies in this thread.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.