Bug #81251 [Dup]: Memory leak with datetime, serialization, and require

From: Date: Mon, 12 Jul 2021 12:52:22 +0000
Subject: Bug #81251 [Dup]: Memory leak with datetime, serialization, and require
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234969@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81251&edit=1 ID: 81251 User updated by: lyrixx at lyrixx dot info Reported by: lyrixx at lyrixx dot info Summary: Memory leak with datetime, serialization, and require Status: Duplicate Type: Bug Package: Variables related Operating System: linux PHP Version: 8.0.8 Assigned To: cmb Block user comment: N Private report: N New Comment: Thanks for the comment. BTW, I noticed that : php test.php => Memory leak php -n test.php => Memory leak php -n -d zend_extension=opcache -d "opcache.enable_cli=on" test.php => NO memory leak ! This is a bit crazy to me. Anyway, I fail to see why the relation with bug #81142. There is **no array** in my case. More over, as I noticed in the initial bug report, if the code don't goes through "require", there is not memory leak. So "unserialize(serialize($foobar))" doesn't leak in my case. Previous Comments: ------------------------------------------------------------------------ [2021-07-12 12:43:00] cmb@php.net This reproduces on PHP-7.4 as well, and is because the different serialized strings are all interned; see bug #81142. ------------------------------------------------------------------------ [2021-07-12 10:05:03] lyrixx at lyrixx dot info Description: ------------ When one require a PHP script, that unserialize some data with an instance of DateTime in it, a memory leak occurs Test script: --------------- <?php class Foobar { public function __construct( // If this property is removed => No leak public DateTime $d, ) { } } for ($i=0; $i < 10000; $i++) { $foobar = new Foobar(new \DateTime()); // 1. Leak when "require" is involved $file = '/tmp/test-serialized.php'; file_put_contents($file, sprintf("<?php return unserialize(base64_decode('%s'));\n", base64_encode(serialize($foobar)))); $o = require $file; // 2. No leak in this case // unserialize(serialize($foobar)); if ($i % 1000 === 0) { printf("%.2fMb\n", memory_get_usage() / 1024 / 1024); } } Expected result: ---------------- 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb 0.38Mb Actual result: -------------- 0.38Mb 0.66Mb 0.90Mb 1.23Mb 1.47Mb 1.87Mb 2.11Mb 2.36Mb 2.60Mb 3.16Mb ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81251&edit=1

« previous php.bugs (#234969) next »