[PD-dev] Destructor in external classes

Funs Seelen funsseelen at gmail.com
Mon Mar 24 14:22:51 CET 2014


Hello all,

While reorganizing my code a question about memory management in Pd arose
in me. If I allocate memory within the constructor space, do I have to free
this myself? If yes, how or where should I do this?

Example:

typedef struct _myclass {
    t_object x_obj;
    t_int* x_ptr;
} t_myclass;

/* constructor */
void *myclass_new(t_symbol *s, int argc, t_atom *argv)
{
    t_myclass *x = (t_myclass *)pd_new(myclass_class);

    x_ptr = (t_int)malloc(32*sizeof(t_int));

    myFunction((int*) x_ptr);

    return (void *)x;
}

Note that I still need this pointer and the memory it's pointing at in the
method space.

Do I have to worry about this or is all memory freed automatically when an
object is removed from its canvas?

Any hints?

Regards,
Funs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20140324/03e1a0c4/attachment.htm>


More information about the Pd-dev mailing list