ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:
I am having a problem of high memory consumption caused by multiple instances of ItemStyles being created for same confiugration at multiple places in all my derived classes. Let's say I have a base class (B.pm ) which has some derived classes D1.pm, D2.pm , D3.pm etc. Now consider in D1.pm ItemStyle being created at two different places for different style as :
my $style1 = $tree-> ItemStyle ('text', -anchor => 'w', -font => 'Time +s 12',-justify => 'right'); my $style2 = $tree->ItemStyle ('text', -anchor => 'e', -font => 'Couri +er 16' -foreground => 'red', -justify => 'left');
Likewise in all the derived classes (D2,D3 etc) ItemStyle with exactly same combination of parameters and different combinations of parameters are getting created and used multiple times, hence consuming high memory . To get rid of this the idea is to create all the ItemStyles globally and store them in the base class and create one ItemStyle per parameter set. May be we can stringify the parameters and use that as a key in the global hash. Each time we need a ItemStyle in a derived class, then it will call a base class function (say getItemStyle ) with all the parameter set. The base class will sort the parameters, so that the order of mentioning the parameters ( -fg => 'red' , -justify => ' right' OR -justify => 'right', -fg => 'red') does NOT matter and NOT create the ItemStyle twice. If ItemStyle with that passed parameter combination is already present then I will return that and reuse otherwise I will create it once and return. Hope, I could explain my problem clearly. Please help me. Thanks. ghosh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ItemStyle causing high memory consumption
by zentara (Archbishop) on Apr 16, 2012 at 15:05 UTC | |
by ghosh123 (Monk) on Apr 16, 2012 at 16:18 UTC | |
by zentara (Archbishop) on Apr 16, 2012 at 18:23 UTC | |
by ghosh123 (Monk) on Apr 17, 2012 at 02:28 UTC | |
by zentara (Archbishop) on Apr 17, 2012 at 11:01 UTC | |
by zentara (Archbishop) on Apr 16, 2012 at 20:33 UTC | |
Re: ItemStyle causing high memory consumption
by zentara (Archbishop) on Apr 16, 2012 at 21:46 UTC |