Women in Technology

Hear us Roar

  What I Hate About Your Programming Language
Subject:   Java; I want a destructor!
Date:   2003-05-19 03:26:12
From:   anonymous2
Response to: Java; I want a destructor!

This is especially true in a object-oriented language. I have a stream. Is it a memory stream or does it represent a file, a socket, or something else that the garbage collector won't release (or that a finalize method will release too late)? If you don't know, then you'll have to remember to try-finally-close that stream. Even when dealing with memory streams. That's convenience?
Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Java; I want a destructor!
    2003-07-08 07:03:53  anonymous2 [View]

    Unfortunately the presence of a destructor poses HUGE problems for a garbage-collected language. The garbage collector can't tell when it's safe to collect an object, it can't just drop all the objects when the program ends, etc. I too missed destructors, but try ... finally ... is a good substitute.

    Don't use finally() (or python's __del__(), for that matter) as you would a destructor. They may never get called. Also, they pose problems for the garbage collector.