Re: setting object data (how do I?)



Paolo Molaro 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 =
$datatree->insert_node_defaults(parent=>$pnode,sibling=>$snode,titles=>[$item]);

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


In the callback I have:

    my $node = $ctree->selection;
    my ($text) = $ctree->get_node_info($node);
    my $gridtype = $node->{gridtype};
    print "$node $gridtype $text\n";

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?:

Jim





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