php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60785 Memory leak in IntlDateFormatter constructor
Submitted: 2012-01-17 22:14 UTC Modified: 2012-05-24 09:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: tim at digicol dot de Assigned: cataphract (profile)
Status: Closed Package: I18N and L10N related
PHP Version: 5.3.9 OS: Linux 2.6.32 x86_64 CentOS 6.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tim at digicol dot de
New email:
PHP Version: OS:

 

 [2012-01-17 22:14 UTC] 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                                                                     

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-17 22:34 UTC] tim at digicol dot de
The phpinfo "intl" section says:

Internationalization support => enabled
version => 1.1.0
ICU version => 4.2.1
 [2012-01-27 22:15 UTC] carloschilazo at gmail dot com
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);
}

?>

?
 [2012-01-31 10:15 UTC] tim at digicol dot de
unset() doesn’t help, it still leaks memory.

(I had already tried this. In my understanding, reusing the $fmt variable should 
effectively unset the old instance anyway.)
 [2012-05-24 08:33 UTC] cataphract@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: cataphract
 [2012-05-24 09:10 UTC] cataphract@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2da2de46a8dc9d44b624c40adb0d6bf698567167
Log: Fixed bug #60785
 [2012-05-24 09:12 UTC] cataphract@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2da2de46a8dc9d44b624c40adb0d6bf698567167
Log: Fixed bug #60785
 [2012-05-24 09:19 UTC] cataphract@php.net
-Status: Assigned +Status: Closed
 [2012-05-24 09:19 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2014-10-07 23:25 UTC] stas@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2da2de46a8dc9d44b624c40adb0d6bf698567167
Log: Fixed bug #60785
 [2014-10-07 23:36 UTC] stas@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2da2de46a8dc9d44b624c40adb0d6bf698567167
Log: Fixed bug #60785
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jan 31 07:01:30 2025 UTC