#34112 [NEW]: Memory leak when initiating COM object and then destroying it
| From: | James_Brigham at hotmail dot com | Date: | Fri, 12 Aug 2005 21:53:41 +0000 |
| Subject: | #34112 [NEW]: Memory leak when initiating COM object and then destroying it | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-83490@lists.php.net to get a copy of this message | ||
From: James_Brigham at hotmail dot com
Operating system: Windows 2000 or Windows 2003
PHP version: 5.0.4
PHP Bug Type: COM related
Bug description: Memory leak when initiating COM object and then destroying it
Description:
------------
I have not compiled any additional modules. The recommended default
php.ini is being used. There is a memory leak when initiating a new COM
object, then running a query against it. After the query even if you use
the unset()function on all the variables, you cannot recover the full
memory, it just keeps climbing. Do you have any ideas of how to clear the
memory in this simple code I have below?
Thanks for taking the time to read this, it is appreciated.
JB
Reproduce code:
---------------
#!c:\php5\ -q
<?php
$aryHost = array("cp2kisu01","cp2kisu02","cp2kisu03"); //this is a
list
of servers running IIS 5 on a windows 2000 platform
$sProcName = "dllhost"; //give the name of the process to check
$wmi = ""; //our comm object
$threadRecords = ""; //comm object result set
$threadcount = ""; //temp variable for looping though each return record.
echo("\r\n\r\n" . str_repeat("*",79) . "\r\n");
echo("Program Start\r\n"); //this is written for command line...
echo("\r\n" . str_repeat("*",79) . "\r\n");
while(true) //loop until the end of time
{
for ($i = 0; $i < count($aryHost); $i++) //loop through each server in
the array
{
$wmi = new
COM("WinMgmts:{impersonationLevel=impersonate}//{$aryHost[$i]}/root/cimv2");
//initialize new COM object
$threadRecords = $wmi->ExecQuery("SELECT * FROM
Win32_PerfRawData_PerfProc_Process WHERE Name = '" . $sProcName . "'");
//execute a wmi query against our com object
foreach ($threadRecords as $threadcount) //loop through the resules
{
echo("Server:[" . $aryHost[$i] . "] Name: " . $threadcount->Name . "
Count: " . $threadcount->ThreadCount . "\r\n"); //for each result output
basic info to the screen
}
echo("\r\nClearing all the used memory for server: " . $aryHost[$i] .
"\r\n\r\n");
unset($wmi); //clear object memory
unset($threadRecords); //clear returned records memory
unset($threadcount); //clear our temp variable we use for our loop
}
echo("\r\n\r\n" . str_repeat("*",79) . "\r\n");
echo("Sleeping.. so we can check the amount of memory consumed
now..\r\n"); //this is written for command line...
echo("\r\n" . str_repeat("*",79) . "\r\n");
sleep(15); //sleep to keep this from being a tight loop and give time to
check the memory loss each loop
}
?>
Expected result:
----------------
D:\Appsupport\IIS_Monitor>php wmi.php
*******************************************************************************
Program Start
*******************************************************************************
Server:[cp2kisu01] Name: dllhost Count: 318
Server:[cp2kisu01] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu01
Server:[cp2kisu02] Name: dllhost Count: 318
Server:[cp2kisu02] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu02
Server:[cp2kisu03] Name: dllhost Count: 333
Server:[cp2kisu03] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu03
*******************************************************************************
Sleeping.. so we can check the amount of memory consumed now..
*******************************************************************************
Server:[cp2kisu01] Name: dllhost Count: 317
Server:[cp2kisu01] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu01
Server:[cp2kisu02] Name: dllhost Count: 310
Server:[cp2kisu02] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu02
Server:[cp2kisu03] Name: dllhost Count: 328
Server:[cp2kisu03] Name: dllhost Count: 10
Clearing all the used memory for server: cp2kisu03
*******************************************************************************
Sleeping.. so we can check the amount of memory consumed now..
*******************************************************************************
^C
D:\Appsupport\IIS_Monitor>
Actual result:
--------------
we gets the counts expected.. but we have a memory loss every run from
this very simple script. Basically I would like to be able to loop this
across 20 servers every 45 seconds.. but with the memory consumption I
cannot feasibly do that. Every added server causes loss of additional
memory.
--
Edit bug report at http://bugs.php.net/?id=34112&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34112&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34112&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34112&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34112&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34112&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34112&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34112&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34112&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34112&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34112&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34112&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34112&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34112&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34112&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34112&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34112&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34112&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34112&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34112&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34112&r=mysqlcfg