Bug #74575 [NEW]: Memory leaks with gc_collect_cycles()

From: Date: Thu, 11 May 2017 16:14:26 +0000
Subject: Bug #74575 [NEW]: Memory leaks with gc_collect_cycles()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209070@lists.php.net to get a copy of this message
From:             roocster at gmail dot com
Operating system: Windows 10 x64
PHP version:      7.1.5RC1
Package:          *General Issues
Bug Type:         Bug
Bug description:Memory leaks with gc_collect_cycles()

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 bug report at https://bugs.php.net/bug.php?id=74575&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74575&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74575&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74575&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74575&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74575&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74575&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74575&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74575&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74575&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74575&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74575&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74575&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74575&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74575&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74575&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74575&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74575&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74575&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74575&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74575&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#209070) next »