PHP Extension Memory Problems
| From: | Bruce Bailey | Date: | Wed, 21 Apr 2004 20:54:24 +0000 |
| Subject: | PHP Extension Memory Problems | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-9469@lists.php.net to get a copy of this message | ||
I have two problems with a PHP extension that I wrote that creates PHP arrays.
1) If I call my extension function that creates PHP arrays and returns them, unless I either unset or assign it to the empty string the process acts like there is a memory leak.
PHP:
For ($I = 0; $I < $count; $I++)
{
$retCd = createArray(&$arr);
unset($arr); // for some reason this is necessary.
}
C Extension in createArray function:
zval *Arr = 0;
if (zend_parse_parameters(argc TSRMLS_CC, "z", &Arr) == FAILURE)
return ;
if (!PZVAL_IS_REF(Arr))
{
zend_error(E_ERROR, "The Arr parameter must be passed by reference");
RETURN_NULL();
}
array_init(Arr);
if (add_assoc_string(Arr, (char *) szFieldName, (char *) szValue, 1) == FAILURE) {
. . .
}
What can I do in my extension to unset or clear the variable so that it doesnt have to be done in the PHP script?
2) For some reason, after the PHP script finishes, the amount of memory as reported by Linux top does not go back down to its initial level. I notice this especially if I create large PHP arrays. This is very likely to be related to the previous problem.
Thanks in advance,
Bruce
_________________________________________________________________
From must-see cities to the best beaches, plan a getaway with the Spring Travel Guide! http://special.msn.com/local/springtravel.armx