in reply to Acky Memory

Anyway, it seems that the objects are not being destructed properly, as you said. This is because some other part of the program that you can't see still has references to them. Each object might have a reference to itself (or to some other object that refers to it) or the Gtk module might have some data structure that refers to all 200 objects. I don't know where these references are, or how to fix them---it is a bug in Gtk that you might want to report.

Here's what I did to check:

use Gtk; Gtk->init; Gtk->set_locale; print "$$\n"; sleep 7; for(1..200) { my $o = new Gtk::Window; bless $o => 'Gtk::MJD'; undef $o; print "$_\n"; } sleep 7; package Gtk::MJD; BEGIN { @ISA = 'Gtk::Window' } sub DESTROY { my $self = shift; print "$self being destroyed.\n"; $self->SUPER::DESTROY; }

This is a little complicated. I take the Gtk::Window ibjects and re-bless them into package Gtk::MJD. This is a package that inherits all of Gtk::Window's methods, so that the objects behave exactly the same. The only exception is the DESTROY method. When Perl thinks it is time to destroy an object, because no part of the program has a reference to it any more, it will call Gtk::MJD::DESTROY. This just prints a message on the terminal and then dispatches to the real DESTROY method via SUPER::DESTROY.

The output from the program shows that the objects are not being destroyed each time through the loop. Instead they are all hanging around until the program exits, and then they are all destroyed at once.

The only thing that can prevent object destruction of an object is an outstanding reference to the object. Since you don't have one (you undefed it) someone else must have one. Therefore it's not your fault.

I suggest that you write up your problem and send it to the Gtk maintainers as a bug report.

Replies are listed 'Best First'.
Gtk module (not) badly behaved (was: Acky Memory)
by Aristotle (Chancellor) on Oct 27, 2002 at 13:07 UTC
    It is worth noting that two years later, this behaviour still persists. I tried Google et all to see whether there maybe was an explicit specification that this behaviour should be expected and came up empty handed. (Of course, if anyone else can point me somewhere I will gladly stand corrected.) It can be a show stopper..

    Makeshifts last the longest.

      Gtk::Window docs say

      Windows which are told to manage() are not deleted until they are sent the destroy signal.
      .

      Tracing this through to Class Gtk::Object reveals a method destroy() which states

      This can be used to tell toplevel widgets that they should die if they are managed().


      Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy