php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66172 Garbage collector won't collect circullar dependecy if SPL classes involved
Submitted: 2013-11-26 03:07 UTC Modified: 2017-01-02 12:19 UTC
From: aleksey at roave dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.6 OS: Any
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: aleksey at roave dot com
New email:
PHP Version: OS:

 

 [2013-11-26 03:07 UTC] aleksey at roave dot com
Description:
------------
This affects all versions with gc, 5.3 to 5.5
Tried script on http://3v4l.org/KmGDj

I can't tell what happens internally, but it looks like garbage collector will not detect and collect circular dependencies if there are SPL classes involved (i suspect other built-in classes are affected too)

Test script:
---------------
https://gist.github.com/Xerkus/7562464/raw/f6d0ff3f1fbc24a3a3ca99ac974571748103ab51/test.php

Expected result:
----------------
Memory stays at about the same level

Actual result:
--------------
Used memory grows constantly

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-26 03:22 UTC] aleksey at roave dot com
Sorry, linked wrong test run
http://3v4l.org/21Tdf
 [2013-11-27 09:28 UTC] colder@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: colder
 [2013-11-27 15:23 UTC] colder@php.net
I have a patch here: https://github.com/colder/php-src/commit/abf152b260dbcc1da1eb850c9f10098b812c67d4

It indeed affects any internal class with hidden (not property-based) state that is not exposed via get_gc, which includes most SPL classes.. This patch is only about SplHeaps/Priority Queues, I will need more time to generalize.
 [2017-01-02 12:19 UTC] nikic@php.net
-Status: Assigned +Status: Closed -Assigned To: colder +Assigned To: nikic
 [2017-01-02 12:19 UTC] nikic@php.net
All cycle leaks for SPL data structures should be fixed in PHP 7.0. As PHP 5.6 is no longer actively supported I'm closing this issue.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 02:01:32 2025 UTC