when to call sysmem_freeptr?

    Mar 08 2013 | 5:34 pm
    I'd like to know when to definitely call sysmem_freeptr
    and why Max crashes in some cases even when pointers are local.
    Maybe it would be great if anyone who reads the post and can think of an unnamed case
    when to call sysmem_freeptr (or handle) or not to just adds it to the post.
    I was getting unsure because of the following method:
    t_object* get_object_by_scr_name(t_generic *x, t_symbol* scr_name_to_find)
        t_object *parent_patcher = NULL;
        t_object* obj_to_find = NULL;
        t_symbol *scr_name_of_obj = NULL;
        t_object *box = NULL;
        //get the object's parent patcher
        t_max_err err = object_obex_lookup(x, gensym("#P"), (t_object **)&parent_patcher);
        if (err != MAX_ERR_NONE)
            //if parent patcher not found
            return NULL;
        box = jpatcher_get_firstobject(parent_patcher); 
            scr_name_of_obj = jbox_get_varname(box); // scripting name
            if (scr_name_of_obj == scr_name_to_find)
                obj_to_find = jbox_get_object(box);
            box = jbox_get_nextobject(box); // iterate
        if (scr_name_of_obj != scr_name_to_find)
            object_error((t_object*)x, "object not found");
    // crashes if all sysmem_freeptr are executed
    //    sysmem_freeptr(parent_patcher);
    //    sysmem_freeptr(scr_name_of_obj);
    //    sysmem_freeptr(box);
        return obj_to_find;

    • Mar 08 2013 | 7:16 pm
      Hi Nicolas,
      yes this helps a lot. Thank you once again!