php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31297 object instantiation/destruction memory leak
Submitted: 2004-12-26 02:48 UTC Modified: 2004-12-26 12:22 UTC
From: kris dot public at kauper dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5CVS-2004-12-26 (dev) OS: Fedora Core 2
Private report: No CVE-ID: None
 [2004-12-26 02:48 UTC] kris dot public at kauper dot net
Description:
------------
While trying to track down a memory leak in my app, I came across this behaviour:

Instantiating an object of a class that contains 9 or more class variables, and then destroying that object, leaves 64 bytes of unreclaimed memory.

Performing the same test with a class that contains 8 or fewer class variables does not result in the same memory leak.

I've tried the supplied test script with PHP 4.3.8/9/10 and the latest CVS version of PHP5, with the same results for each. In each case, I compiled PHP using:

./configure --enable-memory-limit

Reproduce code:
---------------
<?php

// simple class having 9 class variables
class ClassWith9Vars
{
var $a1 = NULL;
var $a2 = NULL;
var $a3 = NULL;
var $a4 = NULL;
var $a5 = NULL;
var $a6 = NULL;
var $a7 = NULL;
var $a8 = NULL;
var $a9 = NULL;
}

// simple class having 8 class variables
class ClassWith8Vars
{
var $a1 = NULL;
var $a2 = NULL;
var $a3 = NULL;
var $a4 = NULL;
var $a5 = NULL;
var $a6 = NULL;
var $a7 = NULL;
var $a8 = NULL;
}

echo ("Starting test using ClassWith9Vars\n");

$m1 = memory_get_usage();

for ($i = 0; $i < 10; $i++)
{
$test =& new ClassWith9Vars();
unset($test);

$m2 = memory_get_usage();
echo ("leak = " . ($m2 - $m1) . "\n");
$m1 = $m2;
}

echo ("Starting test using ClassWith8Vars\n");

$m1 = memory_get_usage();

for ($i = 0; $i < 10; $i++)
{
$test =& new ClassWith8Vars();
unset($test);

$m2 = memory_get_usage();
echo ("leak = " . ($m2 - $m1) . "\n");
$m1 = $m2;
}

?>

Expected result:
----------------
Starting test using ClassWith9Vars
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
Starting test using ClassWith8Vars
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0


Actual result:
--------------
Starting test using ClassWith9Vars
leak = 608
leak = 88
leak = 64
leak = 64
leak = 64
leak = 64
leak = 64
leak = 64
leak = 64
leak = 64
Starting test using ClassWith8Vars
leak = 32
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0
leak = 0


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-26 12:22 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The Zend Engine internally caches some structures for later use, so it\'s perfectly normal that you see this behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 18:01:31 2024 UTC