View unanswered posts | View active topics It is currently Fri Jun 21, 2024 3:12 pm

Reply to topic  [ 1 post ] 
pChart is leaking memory 
Author Message
New pChart user
New pChart user

Joined: Wed Apr 11, 2012 5:48 am
Posts: 1
Post pChart is leaking memory
We use pChart extensively in free software

we have noticed that many users now experience "Fatal error: Allowed memory size of XX bytes exhausted"
(For example here is a user report,88040 )

This problem happens only when graphs are enabled and the report generation is trying to generate graphs using pchart.
Because we generate many graphs in the same http request (the same request will do MANY things including for example generating 20 graphs and fetching the output to include it in a PDF). because it all happens in the same request, memory that is not freed is then not available for next function calls and next graphs.

It would be great if pChart would free memory using unset() calls where necessary (to unset objects).
One way to test for memory that we use in Piwik is:


    * Print memory usage
    * @param string $prefixString
   static public function getMemoryUsage()
      $memory = false;
         $memory = xdebug_memory_usage();
         $memory = memory_get_usage();
      if($memory === false)
         return "Memory usage function not found.";
      $usage = number_format( round($memory / 1024 / 1024, 2), 2);
      return "$usage Mb";

We also have a small class Timer you could reuse:

It directly outputs memory leaks eg.

$t = new Timer();
// do stuff here...

// this will display the memory that was leaked ("new memory allocated") since the timer was instanciated
echo $t->getMemoryLeak();

I know that it can be very tricky to ensure no memory leak in PHP, but this would really help when pushing pCharts with such an extreme use case :-)

Thank you & keep up the great work!!

Wed Apr 11, 2012 6:03 am
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: