|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-26 12:22 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 23 10:00:01 2025 UTC |
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