DESTRUCTOR:
Factor handbook » C library interface » Passing data between Factor and C » Alien destructors


Vocabulary
alien.destructors

Syntax
DESTRUCTOR: word


Word description
Defines four things:
a tuple named word with a single slot holding a c-ptr
a dispose method on the tuple which calls word with the c-ptr
a pair of words, &word and |word, which call &dispose and |dispose with a new instance of the tuple

The word must be defined in the current vocabulary, and must have stack effect ( c-ptr -- ).

Examples
Suppose you are writing a binding to the GLib library, which as a g_object_unref function. Then you can define the function and destructor like so,
FUNCTION: void g_object_unref ( gpointer object ) DESTRUCTOR: g_object_unref

Now, memory management becomes easier:
[ g_new_foo &g_object_unref ... ] with-destructors


Definition