php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37114 memleak in explode
Submitted: 2006-04-17 21:23 UTC Modified: 2006-04-18 08:30 UTC
From: virtuall at virtuall dot info Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Linux, Freebsd
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: virtuall at virtuall dot info
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-17 22:56 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Memory gets freed at the end the script.
 [2006-04-18 07:51 UTC] virtuall at virtuall dot info
Exactly, memory is freed in the end of script, but there is no way to free it in the runtime - and it's a disaster for highly loaded daemons (yes, I write daemons in PHP).
Or are you trying to tell me it's not a bug?
 [2006-04-18 07:54 UTC] derick@php.net
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";
    }
?>

 [2006-04-18 08:26 UTC] virtuall at virtuall dot info
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
 [2006-04-18 08:30 UTC] derick@php.net
If you make a larger loop you will see it stops increasing at some point. Please, leave this matter closed as there is no bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 20:01:33 2025 UTC