Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: Out of memory using chart::clicker

by Peterpion (Acolyte)
on Feb 23, 2014 at 11:17 UTC ( [id://1075882]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Out of memory using chart::clicker
in thread Out of memory using chart::clicker

Hi monks and thanks for all the replies. I continued to work on this over the last couple of days and found that even if everything is declared as my variables inside the sub with nothing global and nothing passed in, the leak still happens, so although I don't feel confident enough to say on my own that the leak is in the module, I think from the replies above that the leak must be in chart::clicker. Heres what I tried and this still leaks:
#!/usr/bin/perl -s -w use strict; use Chart::Clicker; use Chart::Clicker::Data::Series; use Chart::Clicker::Data::DataSet; $| = 1; sub mysub { my @x_axis; my @y_axis; for (my $t=0;$t<200;$t++){ $x_axis[$t] = $t*10; $y_axis[$t] = int(rand(100)); } my $chart = Chart::Clicker->new; my $series = Chart::Clicker::Data::Series->new( keys => \@x_axis, values => \@y_axis, ); my $dataset = Chart::Clicker::Data::DataSet->new( series => [ $series ], ); $chart->add_to_datasets($dataset); $chart->write_output('test.png'); } for (my $x=0;$x<10000;$x++) { &mysub; print "."; }
So I will both report it to the module writer and try to find it next week myself (but its the first time I have delved into such a complicated module so I think it might be quite difficult and I'm not sure how well I will get on). Looking at the dependencies it looks like there are components written in other languages than perl which although I understand some of, they can tend to be very large (ie C) and I don't have any debugging tools set up for that kind of thing (or much experience with memory leaks etc).

Anyway I thought about the problem a bit more and rewrote the program to write out files which contain one graphs worth of data with a header to describe the information required as state (like absolute time etc). This works well but obviously is less elegant, however its probably more in the spirit of perl as it Just Gets The Job Done nicely in the real world. Although I haven't added the code to fork / exec yet, I will perhaps fork a few child processes to do the graph writing (dependent on the number of processors would be nice) to take advantage of dual or quad cores without the complexity and room for errors that threaded code has. These forked processes could then reexec after a particular number of iterations to deal with the memory leaks.

So all in all I think thats a workable solution but it would be nice to find the leaks in the module still. I wonder if the fact that the process is growing so large would slow it down at all? IE does constantly asking for more memory from the OS slow it down much? (and should that affect my decision as to how many charts to let each child process produce before they commit hari kari?)

Lastly a new question has arisen from this but I think its so unrelated that I better post it as a new question but for those who see it, the question relates to this same program (related to how to input a very large amount of data from an external program called from my program). Thanks very much to all who commented.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1075882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found