Edit report at https://bugs.php.net/bug.php?id=60785&edit=1
ID: 60785
Comment by: carloschilazo at gmail dot com
Reported by: tim at digicol dot de
Summary: Memory leak in IntlDateFormatter constructor
Status: Open
Type: Bug
Package: I18N and L10N related
Operating System: Linux 2.6.32 x86_64 CentOS 6.2
PHP Version: 5.3.9
Block user comment: N
Private report: N
New Comment:
If you unset the variable right after you create it, does the memory usage
still
increases?
<?php
printf("Run 'top -p %s' in another shell to watch memory usage grow...\n",
posix_getpid());
for ($i = 1; $i < 500000; $i++)
{
$fmt = new IntlDateFormatter
(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE
);
unset($fmt);
}
?>
?
Previous Comments:
------------------------------------------------------------------------
[2012-01-17 22:34:18] tim at digicol dot de
The phpinfo "intl" section says:
Internationalization support => enabled
version => 1.1.0
ICU version => 4.2.1
------------------------------------------------------------------------
[2012-01-17 22:14:51] tim at digicol dot de
Description:
------------
Each time I create a new IntlDateFormatter instance, PHP 5.3.9 leaks memory.
You
can see in "top" that the RES column (resident size) keeps growing as long as
the
script is running; up to more than 500 MB for my example. (By the way,
memory_get_usage() and the PHP memory limit don't report or act on this.)
I've noticed this because we're using long-running scripts with the
PHP CLI - they eventually die when too much memory is used. This happens to me
with older 5.3.x versions as well.
I tested with PHP 5.3.9 built with "./configure --enable-intl" on 64bit CentOS
6.2, running in VMware Fusion on my Mac.
Thanks for looking into this, and for the great work on PHP!
Test script:
---------------
<?php
printf("Run 'top -p %s' in another shell to watch memory usage grow...\n",
posix_getpid());
for ($i = 1; $i < 500000; $i++)
{
$fmt = new IntlDateFormatter
(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE
);
}
?>
Expected result:
----------------
[digicol@dcxcentos6vm ~]$ /usr/local/src/php-5.3.9/sapi/cli/php leak.php
Run 'top -p 7211' in another shell to watch memory usage grow...
[digicol@dcxcentos6vm ~]$ top -p 7211
top - 00:13:05 up 12:37, 3 users, load average: 0.34, 0.26, 0.34
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 10.1%us, 3.7%sy, 0.0%ni, 79.7%id, 6.1%wa, 0.1%hi, 0.3%si, 0.0%st
Mem: 2054984k total, 1515064k used, 539920k free, 111760k buffers
Swap: 511992k total, 511992k used, 0k free, 121912k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7211 digicol 20 0 406m 21m 10m S 0.0 1.1 0:00.06 php
Actual result:
--------------
[digicol@dcxcentos6vm ~]$ /usr/local/src/php-5.3.9/sapi/cli/php leak.php
Run 'top -p 7211' in another shell to watch memory usage grow...
[digicol@dcxcentos6vm ~]$ top -p 7211
top - 00:01:18 up 12:26, 3 users, load average: 0.95, 0.65, 0.50
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
Cpu(s): 96.0%us, 3.3%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.3%hi, 0.3%si, 0.0%st
Mem: 2054984k total, 1985784k used, 69200k free, 68784k buffers
Swap: 511992k total, 511860k used, 132k free, 122068k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7211 digicol 20 0 908m 524m 10m R 97.9 26.2 1:15.58 php
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60785&edit=1