php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26982 Possible memory leak in variable interpolation
Submitted: 2004-01-20 15:20 UTC Modified: 2004-01-20 22:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: llucax@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b3 (beta3) OS: Debian sid (linux kernel 2.6.0)
Private report: No CVE-ID: None
 [2004-01-20 15:20 UTC] llucax@php.net
Description:
------------
I'm using a php script for a large (batch) process (about 4 hours procesing DB data) and I found the script grows and grows in memory usage. I've searched and simplify the script to see where was the problem and I found that a simple php script is loosing memory when interpolating variables in a string. I don't know if this is exactly a bug or an expected behavior, but I found it weird and very problematic on large scripts.

I'm using Debian GNU/Linux sid with kernel 2.6.0. I've tested the reproduce code in PHP 5.0.0beta3 compiled by myself[1] and with Debian's PHP 4.3.3 package in the cli and apache module interfaces.

[1] PHP 5.0.0beta3 was compiled with this flags:
'./configure' '--prefix=/usr/local/stow/php5' '--enable-memory-limit' '--with-openssl' '--with-zlib' '--enable-bcmath--with-bz2' '--enable-calendar' '--with-curl' '--enable-dba' '--with-db4' '--with-flatfile' '--with-inifile' '--enable-dbase' '--enable-dbx' '--enable-dio' '--enable-exif' '--enable-filepro' '--enable-ftp' '--with-gd' '--with-gettext' '--with-iconv' '--with-mime-magic' '--with-mysql' '--with-ncurses' '--enable-pcntl' '--with-readline' '--enable-sockets' '--with-sqlite' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--enable-yp' '--with-apxs2=/usr/bin/apxs2'
using gcc 3.3.3 (debian package)

Reproduce code:
---------------
<?php
for ($i = 0; $i < 260; $i++)
    echo("Memory usage ($i): ".memory_get_usage()."\n");
?>


Expected result:
----------------
Memory usage (<i>): <mem>

where <i> is the iteration step and <mem> is a constant ammount of memory used by the script. For example:

Memory usage (0): 32224
Memory usage (1): 32224
[snip]
Memory usage (258): 32224
Memory usage (259): 32224


Actual result:
--------------
Memory usage (0): 32224
Memory usage (1): 32272
Memory usage (2): 32296
Memory usage (3): 32320
[snip]
Memory usage (251): 38272
Memory usage (252): 38296
Memory usage (253): 38320
Memory usage (254): 38344
Memory usage (255): 38344
Memory usage (256): 38344
Memory usage (257): 38344
Memory usage (258): 38344
Memory usage (259): 38344

From 254 and up, the ammount of memory used stays constant (excepting when the loop is about 1000000 long, in that case the memory consumption raises a little but then stays constant again).

If I don't use variable interpolation and use the concatenation operator (.), like this:
echo("Memory usage (".$i."): ".memory_get_usage()."\n");
more memory is used in the second iteration but then stays constant:
Memory usage (0): 31880
Memory usage (1): 31928
Memory usage (2): 31928
Memory usage (3): 31928
Memory usage (4): 31928
[snip]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-20 22:16 UTC] sniper@php.net
It's expected behaviour.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 25 00:00:02 2025 UTC