This Week in D: Issue #4
Adam D. Ruppe via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Feb 3 06:36:57 PST 2015
On Tuesday, 3 February 2015 at 05:53:30 UTC, Jeremy DeHaan wrote:
> Yes, they are not guaranteed to run, but isn't that only during
> run time? They are going to be called at the application exit
> to ensure everything is cleaned up.
If the application exits somewhat cleanly (through return from
main or even a thrown exception in D), it will run, though I'm
not sure if that's guaranteed or just an implementation
convenience.
However, if the application exits differently, they won't
necessarily be run. For example, a Unix signal terminating the
process skips all the D cleanup tasks.
Often, this doesn't matter because the operating system will
clean up a lot of resources anyway. But if you are using
something like shared memory with another process, or expect a
file to be written to in a destructor, you'll find those things
never happen.
I had this problem once in simpledisplay.d. When it died by
ctrl+c, the unix SIGINT was sent, and that skipped the
destructors for shared images. As a result, the system eventually
ran out of shared handles and most GUI programs wouldn't start up
anymore until I cleaned it up some other way.
More information about the Digitalmars-d-announce
mailing list