Hi, this interested me a bit, so I tried to setup a simple example of the way to get the ItemStyle from a packaged Tree. This seems to work, but I have no idea how your memory gain would be affected, or if it is the problem you are trying to describe. Anyways, can you reformulate your question in terms of this simple example? Is the fact that all the Style objects are different the cause of the memory gain problem you experience? Are you looking for a setup where only 2 ItemStyle objects are created instead of 4?

Anyways, its a start for other monks who may know more about OO.

#!/usr/bin/perl use warnings; use strict; use Tk; package ZTree; use base qw(Tk::Derived Tk::Tree); require Tk::ItemStyle; Tk::Widget->Construct('ZTree'); sub ClassInit { my ($class, $mw) = @_; #set the $mw as parent $class->SUPER::ClassInit($mw); } # end ClassInit sub Populate { my ( $self, $args ) = @_; print "@_\n"; $self->SUPER::Populate($args); $self->{'tree'} = $self->Tree(); $self->Advertise( Tree => $self->{'tree'} ); my $tree = $self->{'tree'}; $self->{'red_style'} = $tree->ItemStyle('text', -refwindow => $tree +, -bg => 'red'); $self->{'green_style'} = $tree->ItemStyle('text', -refwindow => $tr +ee, -bg => 'green'); $tree->autosetmode; print "2\n"; } 1; package main; use Tk; my $mw = MainWindow->new; $mw->geometry("400x400"); my $tree = $mw->ZTree( -bg => 'white') ; $tree->add(1, -text => 'abcd', -itemtype => 'text', -style => $tree +->{'red_style'}); $tree->add(2, -text => '1234', -itemtype => 'text', -style => $tree +->{'green_style'}); $tree->pack(-fill=>'both',-expand => 1); my $tree1 = $mw->ZTree( -bg => 'black') ; $tree1->add(1, -text => 'abcd', -itemtype => 'text', -style => $tre +e1->{'red_style'}); $tree1->add(2, -text => '1234', -itemtype => 'text', -style => $tre +e1->{'green_style'}); $tree1->pack(-fill=>'both',-expand => 1); my $button1 = $mw->Button( -text=>'Exit', -command=> sub{exit} )->pack +(); my $button2 = $mw->Button( -text=>'Get Styles', -command=> sub{ my $style1 = $tree->entrycget(1, '-style'); print "$style1\n"; my $style2 = $tree->entrycget(2, '-style'); print "$style2\n"; my $style3 = $tree1->entrycget(1, '-style'); print "$style3\n"; my $style4 = $tree1->entrycget(2, '-style'); print "$style4\n"; } )->pack(); Tk::MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: ItemStyle causing high memory consumption by zentara
in thread ItemStyle causing high memory consumption by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.