To be honest, I'm not very agile with object oriented programming , although I can work thru it, if I had code to run. In your case, from reading the description of your classes, it seems that you could define all the ItemStyles in your B base class, if B.pm is derived from Tk::Tree, then make all your D1 , D2, etc. classes as Derived from B. See perldoc Tk::Derived. That way they all inherit the settings. You might want to look at
Using the Option Database. Possibly setting the the Option Database is the way to avoid the memory gain problems. Possibly in B.pm you could access the $mw with the SUPER. Something along the lines of
sub ClassInit
{
my ($class, $mw) = @_;
$class->SUPER::ClassInit($mw);
$mw->optionAdd("*tree*font", $text_font);
$mw->optionAdd("*tree*foreground", $fgcolor);
return $class;
}
I'm sorry I can't help you further, maybe some Object Oriented monk can help you, but I'm totally non-OO in my thinking style. :-)