disposable - Factor Documentation (original) (raw)

disposable
Factor handbook » The language » Deterministic resource disposal » Writing new destructors

Next: new-disposable ( class -- disposable )

Vocabulary
destructors

Class description
Parent class for disposable resources. This class has two slots:

disposed A boolean value, set to true by dispose. Assert that it is false with check-disposed.
continuation The current continuation at construction time, for debugging. Set by new-disposable if debug-leaks? is on.

New instances must be constructed with new-disposable and subclasses must implement dispose*.

Definition

USING: kernel ;

IN: destructors

TUPLE: disposable < identity-tuple
{ disposed boolean initial: f } continuation ;

Methods

USING: destructors destructors.private generic kernel ;

M: disposable dispose
[
[ unregister-disposable ]
[ M\ disposable dispose (call-next-method) ] bi
] unless-disposed ;