[php-src] Issue #12093: Multidimensional array memory leak

From: Date: Thu, 31 Aug 2023 16:06:37 +0000
Subject: [php-src] Issue #12093: Multidimensional array memory leak
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245303@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12093 Author: volkan ### Description Hi, I attempted to unset a multidimensional array and discovered that the variable can be unset, but the script still keeps it in memory. The following code: ```php gc_enable(); $arr = []; getMemory(); for ($i = 0; $i < 5000; $i++) { $d = str_repeat("Hello, world!", 400); $arr[$i][] = $d; } // Clear the sub-arrays foreach (array_keys($arr) as $index) { unset($arr[$index]); } // Clear the sub-arrays foreach ($arr as &$subArray) { unset($subArray); } array_splice($arr, 0); // Remove all elements from the main array unset($arr); gc_collect_cycles(); getMemory(); function getMemory() { echo date("Y-m-d H:i:s") . ' :: ' . round( (memory_get_usage(true) / 1000000), 2 ) . PHP_EOL; } <?php ``` Resulted in this output: ``` 2023-08-31 17:29:31 :: 2.1 2023-08-31 17:29:33 :: 44.04 ``` But I expected this output instead: ``` 2023-08-31 17:29:31 :: 2.1 2023-08-31 17:29:33 :: 2.1 ``` 3v4l.org link: https://3v4l.org/l6N9I#v7.4.33 When I used SplFixedArray instead of $arr = []; It worked fine. 3v4l.org link:: https://3v4l.org/RuH4Q#v7.4.33 PHP version: 7.* and 8.* ### PHP Version PHP 7.4.33 ### Operating System Debian GNU/Linux 10 (buster)

« previous php.bugs (#245303) next »