php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45225 Memory behavior that reminds ie memory leak.
Submitted: 2008-06-10 05:04 UTC Modified: 2008-06-10 16:57 UTC
From: vituko at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.6 OS: Lenny
Private report: No CVE-ID: None
 [2008-06-10 05:04 UTC] vituko at gmail dot com
Description:
------------
Garbage collection works in an unexpected way for me,
when there're crossed references. I discovered it working with large 
databases, Apache crashes sometimes : the thread hangs and 
after /etc/init.d/apache2 restart, it continues working.

Another thing : the only way to get track of references is 
debug_zval_dump (of course it can be done manually) and huge strings 
must be parsed. Further, when mixing true (&) and "php" references 
it's no more possible... or is it?

Only a tought...

Thanks

Reproduce code:
---------------
class a {
	public function __destruct() {
		echo 'destr<br>' ;
	}
}

$a = new a ;
$a -> v = new a ;
$a -> w = new a ;
$a -> v -> w = $a -> w ;
$a -> w -> v = $a -> v ;

unset ($a) ;
echo 'fin<br>' ;
exit ;

Expected result:
----------------
destr
destr
destr
fin

Actual result:
--------------
destr
fin
destr
destr

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-10 10:54 UTC] scottmac@php.net
You've created a cyclic reference and they can't be destroyed until the script has ended.
 [2008-06-10 14:54 UTC] vituko at gmail dot com
Ok, I've always worked with crossed references, what's wrong with them? It's forbiden in php? I think it's a huge limitation, I would have to do garbage collection myself and I only have debug_zval_dump : it's really not very usefull but for debugging purpouses. And I have to choose between true (&) references and "php" references because if both are used, refcount is no more significatif... Can you give me an advice?
 [2008-06-10 16:53 UTC] scottmac@php.net
Cyclic references can't be free'd until request end time due to the fact there is no garbage collector in PHP. There is one in PHP 5.3 that should deal with this as expected.
 [2008-06-10 16:57 UTC] vituko at gmail dot com
thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 05:01:31 2024 UTC