in reply to Out of memory using chart::clicker

Just from glancing at your code, and knowing what memory gluttens packages are, I can see one giant problem. You have a loop which makes 10000 iterations, and in each cycle, you create a new $chart object and it's associated helper objects.

For some reason, I believe your sub mysub{} closure isn't cleaning up all those objects, as you would expect.

In my experience with other graphic modules, this can be avoided by creating only 1 set of global objects, and as you go thru your loops, you clean out and reuse the global object. This prevents the memory problem ... reuse your objects. See perldoc -q clear for how to clear a package. MJD's example code cleans out a package for reuse.


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

Replies are listed 'Best First'.
Re^2: Out of memory using chart::clicker
by Peterpion (Acolyte) on Feb 23, 2014 at 11:25 UTC
    I've got to say, that sounds like a really good thing to try which I never thought of myself. If I am writing something heavy from scratch myself I would use this kind of technique (I always try to think of reducing allocation overhead etc even though I don't know if it really helps in perl but I always have c in the back of my mind) but it just didn't occur to try it this time as I was thinking along the lines of 'must start with new object each time to make sure its nice and clean'. I guess its dependent on the module code working properly though otherwise things like reused arrays of a smaller size second time round might still contain some old data? Regardless it will be an interesting test to run. Thanks