php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46103 ReflectionObject memory leak
Submitted: 2008-09-17 04:26 UTC Modified: 2017-10-10 16:11 UTC
From: jim dot keller at contextsolutions dot net Assigned:
Status: Closed Package: Performance problem
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jim dot keller at contextsolutions dot net
New email:
PHP Version: OS:

 

 [2008-09-17 04:26 UTC] jim dot keller at contextsolutions dot net
Description:
------------
when a reflector is stored in a class property, the reflector appears to stay in memory after the object is destroyed. This could be related to #33595

Reproduce code:
---------------
class testclass {

   protected $_r;

   public function __construct() {

     $this->getr();

   }


   public function getr() {

     if ( !$this->_r ) $this->_r = new ReflectionObject($this);

     return $this->_r;

   }

}

for ( $j = 0; $j < 100; $j++ ) {

  $t = new testclass();
  echo memory_get_usage() . '<br />';
}



Expected result:
----------------
memory usage should stay constant

Actual result:
--------------
memory usage increases with every iteration

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-20 12:38 UTC] felipe@php.net
Try using memory_get_usage(true).
http://docs.php.net/memory-get-usage

I don't found any memory leak.
 [2011-09-27 04:03 UTC] eric dot muyser at gmail dot com
Not bogus. Still an issue in 5.3.8. https://gist.github.com/1244305
 [2011-09-27 05:11 UTC] laruence@php.net
-Status: Bogus +Status: Open -Assigned To: +Assigned To: dmitry
 [2011-09-27 05:11 UTC] laruence@php.net
I can reproduce.. dmitry plz look at this .
 [2011-09-27 05:43 UTC] laruence@php.net
-Assigned To: dmitry +Assigned To:
 [2011-09-27 05:43 UTC] laruence@php.net
hmm, seems not a ZE issue
 [2011-09-27 08:27 UTC] laruence@php.net
it seems because the object pass to ReflectionObject::__construct is stored in a 
custom struct, which can not be reached by gc_collect_cycles.
 [2016-12-17 14:37 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2016-12-17 14:37 UTC] nikic@php.net
Confirming that this still leaks on PHP 7.
 [2016-12-18 16:11 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c1af9f282f62eaf8a5973068ce373a800e0f752c
Log: Fix bug #46103
 [2016-12-18 16:11 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2017-10-10 16:11 UTC] jim dot keller at contextsolutions dot net
I can finally get back to my code!! Thanks!!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 12:01:27 2024 UTC