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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to