Resource disposal anti-patterns
Factor handbook » The language » Deterministic resource disposal

Prev:Writing new destructors


Words which create objects corresponding to external resources should always be used with with-disposal. The following code is wrong:
<external-resource> ... do stuff ... dispose

The reason being that if do stuff throws an error, the resource will not be disposed of. The most important case where this can occur is with I/O streams, and the correct solution is to always use with-input-stream and with-output-stream; see Default input and output streams for details.