|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-04-21 16:45 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
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();