Memory managament problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a problem with memory allocated by PHP, simplified version of
my code

class a
  function runAll()
    $reports = $this->getAllReports();
    foreach ($resports as $report) $this->doReport($report);

  function doReport($report)
    $veryBigObcject1 = new veryBigObject1();
    $veryBigObcject2 = new veryBigObject2();



And while executing only one report at a time everything works well,
but if I try to execute more reports I run out of memory. When I check
allocated memory with memory_get_usage(true) it looks like the unset()
doesn't free any memory. Any tips?

Re: Memory managament problem

Dude wrote:

Quoted text here. Click to load it


Iván Sánchez Ortega -ivan-sanchezortega-es-

A fuerza de ir todo mal, comienza a ir todo bien.

Re: Memory managament problem

In article

Quoted text here. Click to load it

Consider that every time a new (object) is executed, it creates data
structures for that object.  AFAIK, unset doesn't destroy those data
structures and return them to the system.  That's what a compiled
program is for.  php and perl are interpeted rather than compiled.

DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically by ignored]

Re: Memory managament problem

Dude wrote:
Quoted text here. Click to load it

PHP doesn't necessarily release the memory immediately.  Rather, a
garbage collector runs occasionally (depending on system load) and
releases all memory no longer referenced.

If you're not using shared hosting, you can increase the amount of
memory available in your php.ini file.  It may solve your problem, or it
may just delay it for later.

You don't say what veryBigObject is, but if possible I would suggest you
see about reusing the existing objects.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Memory managament problem

Hash: SHA1

Jerry Stuckle wrote:
Quoted text here. Click to load it


try setting the object to null
$veryBigObcject1 = null;

or even within the object, setting some vars to null after using them.

It looks like that unset just only removes the variable, but not the memory used
by this variable.

here are some comments from which tell that setting a var to null works
better then unset:

johannes keler
Version: GnuPG v2.0.11 (GNU/Linux)


Site Timeline