|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
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
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() {



   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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-20 12:38 UTC]
Try using memory_get_usage(true).

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.
 [2011-09-27 05:11 UTC]
-Status: Bogus +Status: Open -Assigned To: +Assigned To: dmitry
 [2011-09-27 05:11 UTC]
I can reproduce.. dmitry plz look at this .
 [2011-09-27 05:43 UTC]
-Assigned To: dmitry +Assigned To:
 [2011-09-27 05:43 UTC]
hmm, seems not a ZE issue
 [2011-09-27 08:27 UTC]
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]
-Status: Open +Status: Verified
 [2016-12-17 14:37 UTC]
Confirming that this still leaks on PHP 7.
 [2016-12-18 16:11 UTC]
Automatic comment on behalf of nikic
Log: Fix bug #46103
 [2016-12-18 16:11 UTC]
-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-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 11:01:23 2021 UTC