Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27979 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21910 invoked by uid 1010); 10 Feb 2007 08:17:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 21895 invoked from network); 10 Feb 2007 08:17:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2007 08:17:51 -0000 X-Host-Fingerprint: 88.64.153.203 dslb-088-064-153-203.pools.arcor-ip.net Received: from [88.64.153.203] ([88.64.153.203:29870] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/29-03629-DAF7DC54 for ; Sat, 10 Feb 2007 03:17:50 -0500 Message-ID: <7C.29.03629.DAF7DC54@pb1.pair.com> To: internals@lists.php.net Date: Sat, 10 Feb 2007 09:17:48 +0100 User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 88.64.153.203 Subject: Memory usage of Scripts From: phpinternals@thunder-2000.com (Mathias Bank) Good morning, I have a little problem with a php script which uses really lots of memory. Until now, I have thought that PHP will free variable memory after the end of a function. But it seems, that this is not true. simple variables: function readData() { $data = file_get_contents("C:/phpProjekte/map1000.db"); $data2 = $data; } function readData2() { $data = file_get_contents("C:/phpProjekte/map1000.db"); $data2 = $data; unset($data); unset($data2); } These two functions need _no memory_, it works fine. recordsets (sqlite): function readData() { $db = sqlite_open('C:/phpProjekte/map1000.db', 0666); $rs = sqlite_query($db, 'Select * from Node'); sqlite_close($db); } function readData2() { $db = sqlite_open('C:/phpProjekte/map1000.db', 0666); $rs = sqlite_query($db, 'Select * from Node'); sqlite_close($db); unset($rs); } With these functions, you will see a _difference in memory usage_. But there is no sqlite_free_result, which would imply, that you have free your memory. I think, this is a bug. The memory should be freed after the end of the script automatically. arrays: function readData() { $arr = array(); for ($i=1; $i<500; $i++) { $arr[$i] = 5; } } function readData2() { $arr = array(); for ($i=1; $i<500; $i++) { $arr[$i] = new test(); } unset($arr); } There is _no difference_. The memory is freed correctly. Objects: class test { public $t = 3; } function readData() { $arr = array(); for ($i=1; $i<500; $i++) { $arr[$i] = new test(); } } function readData2() { $arr = array(); for ($i=1; $i<500; $i++) { $arr[$i] = new test(); } unset($arr); } There is a _difference_: The memory is not freed correctly. I also think this is a bug. Of course, PHP will free used memory after the end of the script, but because PHP could also be used in complex scripts, it would be important, that the garbage collector will do what it promises. I have found the error by creating a squarified cushion treemap. The algo really works good in PHP. But if you have large trees, than PHP needs to much memory. Mathias