Page 1 of 1

Render memory accumulates and crashes in loop

Posted: Sat May 04, 2013 10:19 pm
by 15965760
Scenario:
8 mile long survey is the x axis in feet
y axis is field survey readings at intervals ranging from 2.5 to 7 feet

This results in 6552 data points that require printing at 50 data points per page.

Rough example:

php code to divide into pages with instructions for row # start and end to be selected from database (sql) for each page

then... FOREACH{ page

build the chart

render (puts a copy in the directory even though "file save" instructions feature not working).

back to top of loop for next page select data and build chart, etc.

} end foreach

These eventually have to be PDF and each image is rendered at 1000x600.

After just 14 (137 printed pages required for this 8 mile survey), I get this..

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1000 bytes) in C:\xampp\htdocs\................\sources\GraphicsGD.php on line 587

I do not have an option for blob in database or text file of just image data (which probably would not work either if TeeChart still has to render the data out -- which is where the memory accumulates) and the SVG is not working to play with that (like I said, they eventually have to go to single PDF and it may be possible to save the image data in a way that PDF can be built rather than saving PNG or JPEG) -- but again, those options are not available.

So why is not the memory relieved (imagedestroy) after each render? The image memory accumulates and crashes, how can this be relieved to start each chart fresh at top of loop with no memory of the one before?

Re: Render memory accumulates and crashes in loop

Posted: Thu May 09, 2013 9:51 am
by yeray
Hello,

Please, try to arrange a simple example project we can run as-is to reproduce the problem here.
Also, pleas specify what exact TeeChart build are you using.

Thanks in advance.

Re: Render memory accumulates and crashes in loop

Posted: Thu May 09, 2013 2:30 pm
by 15965760
Below is code from the same TeeChart example I used in the image width thread but with a button, a WHILE loop, and image size of 1000x600 px. I get 14 images before crash.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Line 2D</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
<?php if(!isset($_POST['submit'])){?>
<font face="Verdana" size="2">
  <br />
<form method="post" action="">
  <input type="submit" name="submit" value=" start chart build and render loop ">
</form>
</font> 

<?php
}// end if not isset

if(isset($_POST['submit'])){
        //Includes
        include "../../sources/TChart.php";
	$i=0;
	while($i<100){		
 ++$i;
$chart = new TChart(1000,600);
$chart->getAspect()->setView3D(false);
$chart->getHeader()->setText("2D Line Chart");

$chart->getAxes()->getLeft()->setMinimumOffset(10);
$chart->getAxes()->getLeft()->setMaximumOffset(10);

$chart->getAxes()->getBottom()->setMinimumOffset(10);
$chart->getAxes()->getBottom()->setMaximumOffset(10);

$line1=new Line($chart->getChart());  
$data = Array(10,50,25,175,125,200,175);
$line1->addArray($data);

$line2=new Line($chart->getChart());  
$line2->addXY(0,10);
$line2->addXY(1,15);
$line2->addXY(2,20);
$line2->addXY(3,25);                                       
$line2->addXY(10,30);

/* You can also use one of the following methods , in the case you want to 
specify a text or color for each point :

$line2->addXYColor(x,y,color)
$line2->addXYText(x,y,text)
$line2->addXYTextColor(x,y,text,color)
*/


$line3=new Line($chart->getChart());  
$data = Array(200,175,175,100,65,110,90);
$line3->addArray($data);

foreach ($chart->getSeries() as $serie) {
  $pointer = $serie->getPointer();
  $pointer->setVisible(true);
  $pointer->getPen()->setVisible(false);
  $pointer->setHorizSize(3);
  $pointer->setVertSize(3);  
  
  $marks = $serie->getMarks();
  $marks->setVisible(true);
  $marks->setArrowLength(5);
  $marks->getArrow()->setVisible(false);
  $marks->setTransparent(true);  
}

$line1->getPointer()->setStyle(PointerStyle::$CIRCLE);
$line2->getPointer()->setStyle(PointerStyle::$TRIANGLE);

$line2->getLinePen()->setStyle(DashStyle::$DASH);

$chart->render("chart1-".$i.".png");
//$rand=rand();
print '<font face="Verdana" size="2">Line 2D Style - '.$i.'<p>';
//print '<img src="chart1.png?rand='.$rand.'">'; 

}// end while  

}// end if isset
?>



</body>
</html>
THe on screen result will look like below, and in whatever directory this page is run from, the images will be there numbered.

Line 2D Style - 1

Line 2D Style - 2

Line 2D Style - 3

Line 2D Style - 4

Line 2D Style - 5

Line 2D Style - 6

Line 2D Style - 7

Line 2D Style - 8

Line 2D Style - 9

Line 2D Style - 10

Line 2D Style - 11

Line 2D Style - 12

Line 2D Style - 13

Line 2D Style - 14


Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4000 bytes) in C:\xampp\htdocs\...........\sources\GraphicsGD.php on line 587

Re: Render memory accumulates and crashes in loop

Posted: Fri May 10, 2013 5:02 am
by 15965760
An increase to 128M in TChart.php will increase the number of renders to 35 before memory crashing -- but I had to throw a progress bar into the loop or it times out around 32.

Still needs to have the stream memory restored after each render somehow. Coupled with the memory allocation increase and getting the file save feature fixed so the images can be directed to specific directory would be a start. Then I still have to create the mechanisms for collecting them from directory and compiling into a single PDF.

Re: Render memory accumulates and crashes in loop

Posted: Thu May 23, 2013 2:54 pm
by Pep
Hello,

you're correct, I'm improving the code to release all the memory once the Chart is rendered, or object with same name is recreated.
I'll back to you with the fixes as soon as possible.

Re: Render memory accumulates and crashes in loop

Posted: Fri Jul 05, 2013 1:26 pm
by yeray
Hi,

We've just published a new maintenance release with the fixes Pep mentioned above.
http://www.teechart.net/support/viewtop ... 11&t=14178