Forums > Dev

Memory management for dynamic inlets/outlets

May 24, 2012 | 3:45 pm

Hi folks,

I am experimenting with dynalic inlets/outlets and they work like a charm.
The only thing I am still uncertain about is the memory management associated with them.
I am working on a DSP UI object and I have a scenario where I instantiate dynamic outlets in myobj_new() method as such:

void *myobj_new(t_symbol *s, long ac, t_atom *av)
    t_dictionary *d;
    t_myobj *x;
    long flags;

    if (!(d = object_dictionaryarg(ac, av))) {
        return NULL;
    if (!(x = object_alloc(s_myobj_class))) {
        return NULL;
    flags = 0
            | JBOX_DRAWFIRSTIN
            | JBOX_NODRAWBOX
            | JBOX_DRAWINLAST
            | JBOX_GROWBOTH
    jbox_new(&x->box.z_box, flags, ac, av);
    x->box.z_box.b_firstin = (t_object *)x;

    dsp_setupjbox(&x->box, 1);

    object_obex_store(x, _sym_dumpout, outlet_append((t_object *)x, NULL, NULL));
    x->out_3 = outlet_append((t_object *)x, NULL, gensym("list"));
    x->out_2 = outlet_append((t_object *)x, NULL, gensym("float"));
    x->out_1 = outlet_append((t_object *)x, NULL, gensym("int"));
    outlet_append((t_object *)x, NULL, gensym("signal"));

    attr_dictionary_process(x, d);

    return x;

This will create an object with 1 signal inlet and 1 signal outlet, then it will have 3 more message outlets (accepting ints floats and lists respectively) and finally one dumpout outlet stored in the object’s obex. Great.
In other parts of my code I manage the number of inlets and outlets with the appropriate functions.
Everything works well so far…

Here is myobj_free() method. That’s what I am not so sure about…

static void myobj_free(t_myobj *x)
    // is this freeing all signal inlets and outlets???

    // first remove the dumpout outlet...
    void *outlet = NULL;
    object_obex_lookup(x, gensym("dumpout"), (t_object **)&outlet);
    hashtab_chuckkey(object_obex_get(x), gensym("dumpout"));

    // ...then remove the other outlets


So, at the end of my object’s life what am I supposed to do with regard to outlets memory management ?
Should I free all outlets like the above or is it redundant/unnecessary ?
Will Max take care of that for me like for regular outlets ?
Does the same go for signal outlets?

Thanks in advance for any help.

– Luigi

June 18, 2012 | 4:43 pm

Hi Luigi,

You should never have to worry about freeing outlets. That is taken care of by Max. For inlets you only need to worry if you are creating proxies.


Viewing 2 posts - 1 through 2 (of 2 total)

Forums > Dev