GtkGC shared auto-release

For interest, this is the operative part of the Gtk2::GC shared gc pool
auto-release I mentioned I tried.  The concept is that the GC returned
by the "get" is released automatically when no longer used (from perl),
instead of having to do an explicit Gtk2::GC->release.

The pool get/release maintains a kind of extra reference count on the GC
(on top of its ordinary GObject ref count), so the theory is to hide
that, and from perl just forget a shared GC when you don't want it any

These couple of lines seem to work, and yes it has to be DESTROY, not
FINALIZE_INSTANCE (or so I believe and found).  But maybe there's an
easier way I haven't realized.  If the concept is sound enough what I
don't have is a particularly good name, something suggestive of release
or shared or pool, but still close to the GtkGC or Gtk2::GC which is its

package Gtk2::Ex::GtkGC;
use strict;
use warnings;
use Carp;

our @ISA = ('Gtk2::Gdk::GC');

use constant DEBUG => 1;

sub get {
  my $class = shift;
  my $self = Gtk2::GC->get (@_);
  return bless $self, $class;  # rebless

  my ($self) = @_;
  if (DEBUG) { print "$self destroy, release count ",
                 ($self->{'release_count'}||0), "\n"; }
  while ($self->{'release_count'} > 0) {
    Gtk2::GC->release ($self);

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