Re: [Vala] Some basic questions



On 22/03/2008, Mikael Hermansson <mike tielie gmail com> wrote:
1:

 If I want a copy of Gtk.TreePath I have to use weak but the problem is
 howto free it after use?

 TreePath a;
 weak TreePath b;

 b=a.copy();
 b.[free/unref] <- does not work.

You should never have to free anything in Vala, except where you
specifically choose not to use the automatic memory management (by
using pointers.)  When you get a weak reference to an object, you are
accepting that the object might be free'd even though you still have a
reference to it - this usually implies that the actual management of
that object is totally hidden away inside a library.

 2:

 Another problem probadly a binding bug:

 weak List selection = tw.get_selection().get_selected_rows();

 Because of the weak ref vala will not free the object but howto free it
 manually then??

 Also tried this:

 List selection = tw.get_tree_selection().get_selected_rows();

 but it didnt compile.

Again, you never need to free.  Probably the weak ref is used because
the library might decide to free the object as soon as it is no longer
valid.

 3: Also the model parameter should not be unrefed

 TreeModel model;
 selections=treeviewPlaylist.get_selection().get_selected_rows( out
 model);
 if (selection)
  return ;

 C code will generate:

 GtkTreeModel *model;

 ....(&model)
 if (selection == NULL) {
        g_object_unref(model);  <- WRONG should not unref model
        return 0;
 }

 adding a weak reference fixes the issue but should vala give a warning
 or is the binding wrong?

Should it definitely not be unref'd?  Normally and out parameter will
result in a strong reference being made, and so an unref is needed
when the local variable goes out of scope.  You could well be right in
this case though, I haven't looked at what this code actually does.

-- 
Phil Housley


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]