php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52497 Memory Leak in classes cycle reference
Submitted: 2010-07-30 09:53 UTC Modified: 2010-08-01 21:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tecnico at adam-italia dot it Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.14 OS: CentsOS
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tecnico at adam-italia dot it
New email:
PHP Version: OS:

 

 [2010-07-30 09:53 UTC] tecnico at adam-italia dot it
Description:
------------
Memory Leak in classes cycle reference

Test script:
---------------
class foo  {
	protected $mBar=null;
	
	public function setBar(bar $value){
		$this->mBar=$value;
	}
	
	public function __destruct(){
 		unset($this->mBar);	 	
 	}
}


class bar  {
	protected $mFoo=null;
	protected $mContent=null;
	
	public function __construct() {
		$this->mContent=str_repeat("prova",10000);
	}
	
	public function setFoo(foo $value){
		$this->mFoo=$value;
	}
	public function __destruct(){
 		unset($this->mFoo);	 	
 	}
}



ini_set("memory_limit","32M");		
		
$cont=0;
		
while($cont<1000){
	$cont++;
	$tmp_foo=new Foo();
	$tmp_bar= new Bar();
	
	$tmp_foo->setBar($tmp_bar);
	$tmp_bar->setFoo($tmp_foo);
	unset($tmp_foo, $tmp_bar);				
}

Expected result:
----------------
no mem leak

Actual result:
--------------
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 50001 bytes)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-01 21:17 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-08-01 21:17 UTC] johannes@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

Use 5.3.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 11:01:30 2025 UTC