Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25826 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21238 invoked by uid 1010); 25 Sep 2006 20:22:30 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 21221 invoked from network); 25 Sep 2006 20:22:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2006 20:22:30 -0000 Authentication-Results: pb1.pair.com header.from=jon@gamingsolutions.ca; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jon@gamingsolutions.ca; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain gamingsolutions.ca from 68.142.225.205 cause and error) X-PHP-List-Original-Sender: jon@gamingsolutions.ca X-Host-Fingerprint: 68.142.225.205 smtp107.rog.mail.re2.yahoo.com Received: from [68.142.225.205] ([68.142.225.205:24193] helo=smtp107.rog.mail.re2.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/D0-10614-38A38154 for ; Mon, 25 Sep 2006 16:22:29 -0400 Received: (qmail 53293 invoked from network); 25 Sep 2006 20:22:24 -0000 Received: from unknown (HELO mail.janderson.ca) (jon-anderson@rogers.com@70.27.165.136 with plain) by smtp107.rog.mail.re2.yahoo.com with SMTP; 25 Sep 2006 20:22:24 -0000 Received: from [10.0.0.2] (jon [10.0.0.2]) by mail.janderson.ca (Postfix) with ESMTP id 68A1E3001E3D9 for ; Mon, 25 Sep 2006 15:51:14 -0400 (EDT) Message-ID: <45183A84.3070307@gamingsolutions.ca> Date: Mon, 25 Sep 2006 16:22:28 -0400 User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Object Memory Leakage... From: jon@gamingsolutions.ca (Jon Anderson) I posted this to php-general several days ago, and the only response suggested that perhaps I should forward the question to PHP internals. If what's below isn't expected behavior, I'd be glad to dedicate a few days to helping track down the problem. I've tried what's below on the server cluster in the office, running Debian Sarge i386 (with an x86-64 kernel), PHP 5.0.16, and Apache 2.0.54. I've also tried at home on a Gentoo box (Athlon-MPs) running PHP 5.0.16 and Apache 2.2. Both produce similar results. (If compiled-in/shared module lists, compile options, or any other information would help, I can provide those too.) What's below this sentence is the original text of the message sent to php-general. Sorry folks, this is a long one...I've re-read a bunch of the documentation, and I can't find a solution. In debugging an out of memory condition, I found that PHP doesn't seem to garbage collect unreferenced objects. It seems to work fine for anything other than objects. (Arrays, strings, integers, etc.) Here's a simple example: define a class, create 3 instances, destroy them in reverse order. I would expect that after each unset and/or NULL, the memory usage would go down, they don't. See the output below. test = rand(); } } echo "Initial Memory Usage: " . memory_get_usage() . "\n"; $mb = 6 * 1024 * 1024; echo "Allocating 7 MB of data..."; $dat = ""; for ($x=0;$x<$mb;$x++) { $dat .= "x"; } echo "Memory Usage: " . memory_get_usage() . "\n"; unset($dat,$x,$mb); echo "Unset Usage: " . memory_get_usage() . "\n"; $num = 32767; $objects = array(); echo "Initial Memory Usage (2): " . memory_get_usage() . "\n"; echo "Allocating $num objects..."; for ($x=0;$x<$num;$x++) { $objects[$x] = new Tester(); } echo "Done. Memory Usage: " . memory_get_usage() . "\n"; echo "Freeing $num objects..."; for ($x=0;$x<$num;$x++) { unset($objects[$x]); $objects[$x] = NULL; } echo "Done. Memory Usage: " . memory_get_usage() . "\n"; $mb = 6 * 1024 * 1024; echo "Allocating 7 MB of data..."; $dat = ""; for ($x=0;$x<$mb;$x++) { $dat .= "x"; } This gives: Initial Memory Usage: 44248 Allocating 7 MB of data...Memory Usage: 6335888 Unset Usage: 44448 Initial Memory Usage (2): 44504 Allocating 32767 objects...Done. Memory Usage: 7752920 Freeing 32767 objects...Done. Memory Usage: 2807080 Allocating 7 MB of data... Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1 bytes) in /home/janderson/svn/memtest.php on line 44 Am I missing something? (Is there a force_garbage_collection() function somewhere that I'm missing?) Any suggestions/workarounds/anything would be most appreciated. Cheers, jon