Deterministic Finalization

Object destructor is called immediately when object is removed from memory.

Object is removed from memory when it goes out of scope (eg. local variables created on the stack in C++ go out of scope when the method completes)


A similar effect is achieved in GarbageCollected environments with an idiom like:

    |file|
    [ file := File open: 'filename.txt'.
      self use: file.
    ] ensure: [file close].

The file will be closed in a deterministic, statically scoped way. This idiom can be generalised more by using block closures, thus:

    File
        withOpen: 'filename.txt'
        do: [:file| self use: file].

or whatever.


I have seen numerous discussions/arguments about the usefulness (or not) of DF in a garbage-collected world, or indeed whether it's possible to elegantly integrate determinism into garbage-collected languages (I'm talking about releasing memory here, not external resources/handles). Is it really an either/or decision, or are there languages which deal with the problem (if it really is a problem) successfully?


EditText of this page (last edited August 15, 2002) or FindPage with title or text search