Bug #79504 [Opn]: json_decode memory leak
| From: | sjon@php.net | Date: | Wed, 22 Apr 2020 06:32:50 +0000 |
| Subject: | Bug #79504 [Opn]: json_decode memory leak | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226707@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79504&edit=1
ID: 79504
Updated by: sjon@php.net
Reported by: lyrixx at lyrixx dot info
Summary: json_decode memory leak
Status: Open
Type: Bug
Package: *General Issues
Operating System: linux
PHP Version: 7.4.5
Block user comment: N
Private report: N
New Comment:
this is not an issue with json, the same can be reproduced by doing simply:
<?php
ini_set('memory_limit', -1);
function m(){ echo round(memory_get_usage() / 1024 / 1024, 2) . "\n"; }
m();
$l=[];
for ($i = 0; $i < 2e6; $i++)
array_push($l, (object)["url"=>"https://www.example.org/"]);
m();
unset($l);
m();
gc_mem_caches();
m();
gc_collect_cycles();
m();
Previous Comments:
------------------------------------------------------------------------
[2020-04-21 16:45:59] lyrixx at lyrixx dot info
Description:
------------
Hello
I notice a bug in
json_decode().
With the following script, the memory is not reclaimed.
But if I use json_decode($content, true); the memory is well reclaimed.
By the way, I'm not sure it's an issue with JSON, may be it's only about objects
Test script:
---------------
<?php
ini_set('memory_limit', -1);
function m()
{
echo round(memory_get_usage() / 1024 / 1024, 2) . "\n";
}
m();
$content = file_get_contents('https://gist.githubusercontent.com/lyrixx/3542faea462e5d101d0d755886ea79bd/raw/b83466f2dc61348e414d3507eeb5740f7751e8f3/file.json');
m();
$data = json_decode($content);
m();
unset($content, $data);
m();
gc_mem_caches();
m();
gc_collect_cycles();
m();
Expected result:
----------------
0.56
75.01
754.69
0.56
0.56
0.56
Actual result:
--------------
0.56
75.01
817.65
16.55
16.55
16.55
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79504&edit=1