Arifin has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am getting some "out of memory" error while trying to run a perl script I wrote. I googled for this but failed to fix, and thought if you could shed some light. Basically, I am using the CPAN module GraphViz to create a graph from my input data (say, from a file named full.txt). Now, I am reading just one line at a time, so the error is not due to large input filesize. I tracked the error and found that it gets in trouble when, at the end, it is trying to save the graph (data structure) as a .png (or .gif) file. So, commenting out this line does not crash the program:
$g->as_png("1.png"); # save the graph as a png image
I tested on a small input file and it successfully produced the desired .png file.
The errors are:
dot(3100) malloc: *** vm_allocate(size=1069056) failed (error code=3)
dot(3100) malloc: *** error: can't allocate region
dot(3100) malloc: *** set a breakpoint in szone_error to debug
out of memory
Any clue on how I can increase the memory or get around this in any other way?
Here is my perl script:
#!/usr/bin/perl -w use GraphViz; use strict; use warnings; my $inputfile = $ARGV[0]; open(INPUTFILE, $inputfile) || die "Could not open $inputfile\n"; my $start_run = time(); # get timestamp at the beginning of creatin +g the graph my $countLine = 0; # count matched I-lines of text my $g = GraphViz->new(); # create a new graph while (my $line = <INPUTFILE>) { chomp($line); if( $line =~ m/\bI\b/i ) { # Does $line has an uppercase 'I' anyw +here in it? #print "$line\n"; $countLine++; # Split the I-line into 5 fields my ($timestamp, $field2, $temple, $macaque1, $macaque2) = split ' +', $line; print "$timestamp : $temple : $macaque1 : $macaque2\n\n"; # Add an edge to the graph for this I-line $g->add_edge( $macaque1 => $macaque2, label => "$timestamp\n$temp +le"); } } $g->as_png("1.png"); # save the graph as a png image my $end_run = time(); # get timestamp at the end of creating the graph my $run_time = $end_run - $start_run; print "Job took $run_time seconds. Processed $countLine I-lines of tex +t.\n"; close(INPUTFILE);

Replies are listed 'Best First'.
Re: out of memory error in using GraphViz
by Anonymous Monk on Feb 16, 2009 at 19:55 UTC
    Thats a bug in the graphviz/dot program, you probably need to upgrade.
Re: out of memory error in using GraphViz
by pemungkah (Priest) on Feb 24, 2009 at 21:43 UTC
    graphviz (the renderer) is unfortunately prone to problems with very large graphs (which I'm guessing yours is). Is there any way to reduce the number of nodes you want to graph?

    As an alternative, you may be able to save the graph in "canonical" format (that is, the actual dot source that would render the graph) and use ZGRViewer to visualize it - this program renders graphs as SVG and handles very large graphs better.

    Upgrading may possibly help out, but I don't hold out hope that it will for sure fix your problem.