with-destructors ( quot -- )
Factor handbook » The language » Deterministic resource disposal » Using destructors

Prev:dispose-each ( seq -- )
Next:&dispose ( disposable -- disposable )


Vocabulary
destructors

Inputs
quota quotation


Outputs
None

Word description
Calls a quotation within a new dynamic scope. This quotation may register destructors using &dispose or |dispose. The former registers a destructor that will always run whether or not the quotation threw an error, and the latter registers a destructor that only runs if the quotation throws an error. Destructors are run in reverse order from the order in which they were registered.

Notes
Destructors generalize with-disposal. The following two lines are equivalent, except that the second line establishes a new dynamic scope:
[ X ] with-disposal [ &dispose X ] with-destructors


Examples
[ 10 malloc &free ] with-destructors


Definition