Re: setting object data (how do I?)

On 06/27/01 Jim Edwards wrote:
Note, however, that every Gtk::Object is a hash reference and
you can use it to store data with the object itself:

        $object->{mydata} = "stuff";

Either I've found a memory leak or you can't rely on this method:

In the initialization subroutine I have:

  foreach $item (@{$list->{$gridtype}}) {
     $snode =

     $snode->{gridtype} = $gridtype;
     print "$snode $item $gridtype\n";

$snode is not a Gtk::Object, so you should not use that technique.

Now the $text is correct, but the $node is a different memory location than that
originally assigned and gridtype is lost.  I think that Gtk Perl uses hashs to
store it´s data but it doesn´t nessasarily keep them around, instead it relies
on the c side to do that.  Can anyone confirm or deny this theory?:

Only types derived from Gtk::Object are guaranteed to be hash references
and you can safely store your data in them.
The other types may or may not work that way: this basically depends
on how the C library implements and memory-manages them, so don't
rely on that feature even for the misc objects that happen to support it.
GtkCTreeNode is a C struct that is not reference counted, so we
can't guarantee for how much time the data in it will be valid,
just use it and forget about it as soon as possible:-)
Oh, and you may bug the Gtk+ team so they provide more sensible interfaces 
next time...

If you need to store data on a per-node basis, you have two
*) use set_row_data(), get_row_data(), but note that the data must be
   a reference
*) add an additional (hidden) column and store your data as text in it.


lupus debian org                                     debian/rules
lupus ximian com                             Monkeys do it better

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