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
In reply to ItemStyle causing high memory consumption by ghosh123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |