4

Possible Duplicate:
Finding cause of memory leaks in large PHP stacks

What are common causes of PHP memory leaks? I'm looking for things that are commonly done by unsuspecting PHP programmers that cause memory leaks.

Community
  • 1
  • 1
TaylorOtwell
  • 7,177
  • 7
  • 32
  • 42
  • like [these](http://stackoverflow.com/search?q=php+memory+leak)? – Kevin Peno Apr 22 '11 at 16:35
  • You might try giving us a few more specifics about your question. The normal things might include firing off a thread and forgetting about it or the like, but if you have a specific instance in which you are trying to hunt down a leak you might let us know the circumstances. – Andy Apr 22 '11 at 16:35
  • Maybe the fact that it's PHP? ;) – ThiefMaster Apr 22 '11 at 16:41
  • 1
    Please be aware that leaking memory in a PHP script is *usually* not a big deal, as most scripts have a very short lifetime. You only really need to worry about this for long-running PHP processes, such as daemons. You should also read about [PHP 5.3's new garbage collection mechanism](http://us2.php.net/manual/en/features.gc.php), which can take care of circular references, a common source of "leaked" memory. – Charles Apr 22 '11 at 16:58

1 Answers1

1

The most common cause of leaks is circular references. However, as of PHP 5.3, those are now detected and taken care of.

So now the only causes of "leaks" should be:

  • A bug with PHP (I don't know of any offhand; check the active bug reports.)

  • Building large (for instance) arrays or strings that you never "free" (i.e., You continue to reference them)

So in short, there shouldn't be much of a problem if you remember to stop referencing data you no longer need.

Matthew
  • 47,584
  • 11
  • 86
  • 98