What I Hate About Your Programming Language
Subject:   Java; I want a destructor!
Date:   2003-05-15 01:11:36
From:   anonymous2
Response to: Java; I want a destructor!

That would be completely stupid. The whole point of the destructor is to free heap memory that might have been allocated as part of a data structure. Java has pretty good garbage collection, so this saves you the hassle. I mean, instead of saying delete blah, you can just say blah.finish() if all you are trying to do is complete something before the object is gotten rid of. This sort of thing can be equally easily done in Java without any explicit call that is reserved for freeing memory.
Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Java; I want a destructor!
    2003-05-18 18:20:29  anonymous2 [View]

    The purpose of a destructor is to free resources (not just heap memory). Closing files, sockets, database connections, etc., even in the presence of exceptions, without having to remember to try-finally-release them can be quite powerful. Garbage collection is nice and has its place, but isn't a panacea.