php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44810 xml_set_object memory leak
Submitted: 2008-04-23 17:50 UTC Modified: 2008-04-23 18:57 UTC
From: luka8088 at gmail dot com Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5.2.5 OS: Windows
Private report: No CVE-ID: None
 [2008-04-23 17:50 UTC] luka8088 at gmail dot com
Description:
------------
xml_set_object causes memory leak....

in example, an infinite loop i written which should not constantly increase memory...

When xml_set_object($this->parser, &$this); is removed, memory leak stops...

Reproduce code:
---------------
class xml
	{
	function __construct()
		{
		$this->parser = xml_parser_create();
		xml_set_object($this->parser, &$this);
		}
	
	function __destruct()
		{
		xml_parser_free($this->parser);
		}
	}

while (true)
	{
	usleep(1000);
	$x = new xml();
	unset($x);
	}

Expected result:
----------------
Nothing should happen ....

Actual result:
--------------
when below code is run.. memory usage increases 5 MB/s for abount 15 seconds and then:

PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried to allocate 16 bytes) in D:\source\php\include\xml.php on line 18
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate
16 bytes) in D:\source\php\include\xml.php on line 18

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-23 18:57 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You have a circular reference here.

$this->parser refers to itself, so when you unset($x) it only frees the instance of $xml, but the object will still exist because it has references to the parser. Therefore __destruct is never called to free the parser.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC