|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-17 21:23 UTC] virtuall at virtuall dot info
Description:
------------
It's a strange that nobody has noticed a memleak in such an essential function. This needs no comments, does it?
Reproduce code:
---------------
<?php
echo memory_get_usage() . "\n";
explode(' ', 'blah foo bar');
echo memory_get_usage() . "\n";
?>
Expected result:
----------------
40824
40824
Actual result:
--------------
40824
41120
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 20:00:01 2025 UTC |
This is not a bug... PHP caches some internal things. If you run this script you'll see it only "leaks" once... but it's just a cached allocation: <?php echo memory_get_usage(), "\n"; for ($i = 0; $i < 100; ++$i) { explode(' ', 'blah foo bar'); echo memory_get_usage(), "\n"; } ?>Hmm... indeed in this example it happens only once, but it did leak in my daemon, so I tried to reproduce that code. And it looks like it happens only when there are 8 or more separators in the string: <?php echo memory_get_usage(), "\n"; for ($i = 0; $i < 20; ++$i) { explode('.', '........'); echo memory_get_usage(), "\n"; } ?> and there it goes... 41008 41816 41880 41944 42008 ... try that with 7 dots and it will work fine! 41016 41704 41704 41704 ... don't say it isn't a bug either