On 09/14/2012 05:21 PM, Derek Dai wrote:
> Hi:
> 
> For example,
> Clutter.Color bg;
> Clutter.Actor rect = new Clutter.Rectangle();
> rect.get("background-color", out bg);
> 
> Since GObject.get() will return a copied Clutter.Color, the second
> parameter must be a pointer to a Clutter.Color pointer (ClutterColor **).
> But since you actually pass in a Clutter.Color pointer (ClutterColor *),
> what you got is address filled in first 4 bytes of bg and memory leak, in
> this example.
> 
> I tried this way
> Clutter.Color * bg;
> Clutter.Actor rect = new Clutter.Rectangle();
> rect.get("background-color", out bg);
> 
> bg will point to returned Clutter.Color, but I don't know the right way to
> free it.

While I'm a bit sceptical about your premise (I would have assumed that
g_object_get would simply copy the structure into memory you provide, as
in your original example - but I don't know a lot about GObject, or
clutter), this is how to free the memory, assuming g_object_new does
return a pointer to memory that you're responsible for:

delete bg;


> In clutter-1.0.vapi, Clutter.Color has free() method, I can invoke
> it like
> bg->free();
> 
> But Vala code generator will copy it into another Clutter.Color (just like
> another primitive types) which is on the stack and pass it to the
> Clutter.Color.free(), eg.
> ClutterColor * tmp5;
> tmp5 = * bg;
> clutter_color_free(& tmp5);
> 
> This causes glibc dumpping and aborting our process. I also tried free with
> delete keyword, but with no luck, the generated C code simple free with
> g_free()
> g_free(bg);
> 
> Derek Dai
> 
> 
> On Fri, Sep 14, 2012 at 8:00 PM, <vala-list-requ...@gnome.org> wrote:
> 
>> eed to do
> 
> 
> 
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
> 

_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to