disposable
Factor documentation > 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 three slots:
disposed - boolean. Set to true by dispose. Assert that it is false with check-disposed.
id - unique identifier. Set by new-disposable.
continuation - 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 ;