|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-11-13 17:01 UTC] lars_teuber at gmx dot de
Description:
------------
Hi,
DateTime::createFromFormat() has a memory leak.
Tested with: 5.3.14, 5.4.4, 5.5.3
Best regards
Lars Teuber
Test script:
---------------
<?php
$mem_start = memory_get_usage(true);
echo 'start: ' . $mem_start . '<br>';
$max_iterations = 1000000;
for ($i = 1; $i <= $max_iterations; $i++) {
DateTime::createFromFormat('M/D/Y H:i:s', '2013-11-12 20:00:00');
if (($i % 100000) == 0) {
echo $i . '.: ' . memory_get_usage(true) . '<br>';
}
}
$mem_end = memory_get_usage(true);
echo 'end: ' . $mem_end . '<br>';
echo 'diff end-start: ' . ($mem_end - $mem_start) . '<br>';
?>
Expected result:
----------------
(more or less) constant memory usage
Actual result:
--------------
start: 524288
100000.: 16777216
200000.: 33030144
300000.: 53477376
400000.: 65536000
500000.: 77594624
600000.: 106168320
700000.: 118226944
800000.: 130285568
900000.: 142344192
1000000.: 154140672
end: 154140672
diff end-start: 153616384
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 03:00:01 2025 UTC |
Here's the valgrind output for test.php: for ( $i = 0; $i < 100000; $i++ ) { $d = DateTime::createFromFormat('m-d-Y', '05-21-2014'); unset($d); } valgrind --leak-check=yes --leak-check=full --show-leak-kinds=all php test.php ==21278== 5,922 bytes in 416 blocks are still reachable in loss record 14 of 18 ==21278== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21278== by 0x698C679: strdup (strdup.c:42) ==21278== by 0x48BCB4: ??? (in /usr/bin/php5) ==21278== by 0x48C164: timelib_builtin_db (in /usr/bin/php5) ==21278== by 0x46D1CC: php_date_initialize (in /usr/bin/php5) ==21278== by 0x46D41D: zif_date_create_from_format (in /usr/bin/php5) ==21278== by 0x6DD6BA: dtrace_execute_internal (in /usr/bin/php5) ==21278== by 0x79D714: ??? (in /usr/bin/php5) ==21278== by 0x717447: execute_ex (in /usr/bin/php5) ==21278== by 0x6DD5B8: dtrace_execute_ex (in /usr/bin/php5) ==21278== by 0x6EF03F: zend_execute_scripts (in /usr/bin/php5) ==21278== by 0x68EF24: php_execute_script (in /usr/bin/php5) ==21278== ==21278== 8,168 bytes in 1 blocks are still reachable in loss record 15 of 18 ==21278== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21278== by 0x48BB48: ??? (in /usr/bin/php5) ==21278== by 0x48C164: timelib_builtin_db (in /usr/bin/php5) ==21278== by 0x46D1CC: php_date_initialize (in /usr/bin/php5) ==21278== by 0x46D41D: zif_date_create_from_format (in /usr/bin/php5) ==21278== by 0x6DD6BA: dtrace_execute_internal (in /usr/bin/php5) ==21278== by 0x79D714: ??? (in /usr/bin/php5) ==21278== by 0x717447: execute_ex (in /usr/bin/php5) ==21278== by 0x6DD5B8: dtrace_execute_ex (in /usr/bin/php5) ==21278== by 0x6EF03F: zend_execute_scripts (in /usr/bin/php5) ==21278== by 0x68EF24: php_execute_script (in /usr/bin/php5) ==21278== by 0x79F6ED: ??? (in /usr/bin/php5) ==21278== ==21278== 9,029 bytes in 594 blocks are still reachable in loss record 16 of 18 ==21278== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21278== by 0x698C679: strdup (strdup.c:42) ==21278== by 0x48B994: ??? (in /usr/bin/php5) ==21278== by 0x48C15F: timelib_builtin_db (in /usr/bin/php5) ==21278== by 0x46D1CC: php_date_initialize (in /usr/bin/php5) ==21278== by 0x46D41D: zif_date_create_from_format (in /usr/bin/php5) ==21278== by 0x6DD6BA: dtrace_execute_internal (in /usr/bin/php5) ==21278== by 0x79D714: ??? (in /usr/bin/php5) ==21278== by 0x717447: execute_ex (in /usr/bin/php5) ==21278== by 0x6DD5B8: dtrace_execute_ex (in /usr/bin/php5) ==21278== by 0x6EF03F: zend_execute_scripts (in /usr/bin/php5) ==21278== by 0x68EF24: php_execute_script (in /usr/bin/php5) ==21278== ==21278== 16,384 bytes in 1 blocks are still reachable in loss record 17 of 18 ==21278== at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21278== by 0x48BA89: ??? (in /usr/bin/php5) ==21278== by 0x48C15F: timelib_builtin_db (in /usr/bin/php5) ==21278== by 0x46D1CC: php_date_initialize (in /usr/bin/php5) ==21278== by 0x46D41D: zif_date_create_from_format (in /usr/bin/php5) ==21278== by 0x6DD6BA: dtrace_execute_internal (in /usr/bin/php5) ==21278== by 0x79D714: ??? (in /usr/bin/php5) ==21278== by 0x717447: execute_ex (in /usr/bin/php5) ==21278== by 0x6DD5B8: dtrace_execute_ex (in /usr/bin/php5) ==21278== by 0x6EF03F: zend_execute_scripts (in /usr/bin/php5) ==21278== by 0x68EF24: php_execute_script (in /usr/bin/php5) ==21278== by 0x79F6ED: ??? (in /usr/bin/php5) ==21278== ==21278== 43,264 bytes in 416 blocks are still reachable in loss record 18 of 18 ==21278== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21278== by 0x48BC85: ??? (in /usr/bin/php5) ==21278== by 0x48C164: timelib_builtin_db (in /usr/bin/php5) ==21278== by 0x46D1CC: php_date_initialize (in /usr/bin/php5) ==21278== by 0x46D41D: zif_date_create_from_format (in /usr/bin/php5) ==21278== by 0x6DD6BA: dtrace_execute_internal (in /usr/bin/php5) ==21278== by 0x79D714: ??? (in /usr/bin/php5) ==21278== by 0x717447: execute_ex (in /usr/bin/php5) ==21278== by 0x6DD5B8: dtrace_execute_ex (in /usr/bin/php5) ==21278== by 0x6EF03F: zend_execute_scripts (in /usr/bin/php5) ==21278== by 0x68EF24: php_execute_script (in /usr/bin/php5) ==21278== by 0x79F6ED: ??? (in /usr/bin/php5)I think I've found situation when the memory leak occurs. Memory is leaked only when you try to parse invalid date. Here's example script: for ( $i = 0; $i < 10000; $i++ ) { $d = DateTime::createFromFormat('m-d-Y', 'asdf asdf'); unset($d); if ($i % 100 == 0) { echo 'Memory usage: ', memory_get_usage(), PHP_EOL; } }