Bug #74575 [Opn->Nab]: Memory leaks with gc_collect_cycles()
| From: | nikic@php.net | Date: | Sun, 25 Jun 2017 17:07:00 +0000 |
| Subject: | Bug #74575 [Opn->Nab]: Memory leaks with gc_collect_cycles() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209676@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74575&edit=1
ID: 74575
Updated by: nikic@php.net
Reported by: roocster at gmail dot com
Summary: Memory leaks with gc_collect_cycles()
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 7.1.5RC1
Block user comment: N
Private report: N
New Comment:
$a is a reference in your example, so the $a = $a[0] assignment already breaks the cyclce. As such,
gc_collect_cycles() has nothing to collect.
Previous Comments:
------------------------------------------------------------------------
[2017-05-11 16:32:56] roocster at gmail dot com
The bug is also reproduced on linux
------------------------------------------------------------------------
[2017-05-11 16:14:20] roocster at gmail dot com
Description:
------------
If make the situation described in the docs of "Collecting Cycles"
(http://php.net/manual/en/features.gc.collecting-cycles.php) the gc_collect_cycles() doesn't
collect garbage cycle reference.
After we made an array which is referenced only by itself element (cycle reference) the
gc_collect_cycles() call returns 0. That means there are not collected cycles and we have a memory
leak.
If we replace "$a = $a[0]" on "unset($a)" the garbage collector works correctly
and the gc_collect_cycles() call returns 1.
Test script:
---------------
<?php
echo "Memory usage before memory leak:\t",
memory_get_usage()," bytes",PHP_EOL;
$a = ['one'];
$a[] = &$a;
$a = $a[0];
echo "Memory usage after memory leak:\t\t",
memory_get_usage()," bytes",PHP_EOL;
echo "Number of collected cycles: ",
gc_collect_cycles(),PHP_EOL;
echo "Memory usage after gc_collect_cycles():\t",
memory_get_usage()," bytes",PHP_EOL;
Actual result:
--------------
Memory usage before memory leak: 353368 bytes
Memory usage after memory leak: 353392 bytes
Number of collected cycles: 0
Memory usage after gc_collect_cycles(): 353392 bytes
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74575&edit=1