[PD-dev] Destructor in external classes
IOhannes m zmölnig
zmoelnig at iem.at
Mon Mar 24 14:45:10 CET 2014
On 03/24/2014 02:22 PM, Funs Seelen wrote:
> 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?
yes
> If yes, how or where should I do this?
the destructor is called "free_method" in Pd-lingo and is set via
class_new() [1].
so you basically would do:
void myclass_free(t_myclass*x) {
free(x->x_ptr);
}
// ...
void myclass_setup(void) {
class_new(gensym("myclass"), myclass_new, myclass_free,
sizeof(t_myclass), 0, ...);
}
> Do I have to worry about this or is all memory freed automatically when an
> object is removed from its canvas?
no magic is involved, thus you have to take care yourselves.
mdsa
IOhannes
[1] http://iem.at/pd/externals-HOWTO/node9.html#SECTION00092100000000000000
>
> Example:
>
>
> Any hints?
>
> Regards,
> Funs
>
>
>
> _______________________________________________
> Pd-dev mailing list
> Pd-dev at iem.at
> http://lists.puredata.info/listinfo/pd-dev
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 880 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20140324/1048cdbc/attachment.pgp>
More information about the Pd-dev
mailing list