<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hello all,<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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?<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Example:<br><br>typedef struct _myclass {<br>    t_object x_obj;<br>    t_int* x_ptr;<br>} t_myclass;<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
/* constructor */<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">void *myclass_new(t_symbol *s, int argc, t_atom *argv)<br>{<br>    t_myclass *x = (t_myclass *)pd_new(myclass_class);<br>
<br>    x_ptr = (t_int)malloc(32*sizeof(t_int));<br><br>    myFunction((int*) x_ptr);<br><br>    return (void *)x;<br>}<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Note that I still need this pointer and the memory it&#39;s pointing at in the method space.<br>
<br> Do I have to worry about this or is all memory freed automatically when an object is removed from its canvas?<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Any hints?<br><br></div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Funs<br></div></div>