php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20844 "array()" doesn't free memory
Submitted: 2002-12-05 16:55 UTC Modified: 2002-12-06 01:23 UTC
From: busia at tiscali dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.0RC2 OS: Redhat 7.0
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: busia at tiscali dot it
New email:
PHP Version: OS:

 

 [2002-12-05 16:55 UTC] busia at tiscali dot it
If I run this script:

<?
ini_set('memory_limit','100M');
echo "a";
$array=array();
for($i=0; $i<=500000; $i++) $array[]="pippoplu";
echo "b\n";
sleep(15);
$array=array();
echo "c\n";
sleep(15);
for($i=0; $i<=300000; $i++) $array[]="pippoplu";
echo "d\n";
sleep(15);
?>

and I watch the memory usage i see:
after the 'echo "a"': memory usage increases and it reaches 64MB (all is ok)
after the 'echo "b"': memory usage is 64MB (all is ok)
after the 'echo "c"': memory usage is 62MB (not ok)
after the 'echo "d"': memory usage remains 62MB (not ok)

Why '$array=array();' don't free the memory used by $array?
and why the memory don't increases when between ' echo "c"' and 'echo "d"'?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-05 17:01 UTC] busia at tiscali dot it
If I add the line
unset($array);
before
$array=array(); (line: 8)
the result remains the same.
 [2002-12-05 17:06 UTC] busia at tiscali dot it
I have reproduced the problem also on an ther server (this server uses redhat 7.2)
 [2002-12-06 01:23 UTC] derick@php.net
This is not at all a problem in PHP, but rather a UNIX behavior. While dumping the real in-use memory by PHP with help of xdebug, you see that it clearly frees the memory internally:

$ php bug20884.php 
35728a
38133048b
50192c
23733064d

modified script:

<?php
xdebug_start_trace();
ini_set('memory_limit','100M');
echo xdebug_memory_usage();
echo "a\n";
$array=array();
for($i=0; $i<=500000; $i++) $array[]="pippoplu";
echo xdebug_memory_usage();
echo "b\n";
sleep(15);
$array=array();
echo xdebug_memory_usage();
echo "c\n";
sleep(15);
for($i=0; $i<=300000; $i++) $array[]="pippoplu";
echo xdebug_memory_usage();
echo "d\n";
sleep(15);
?>

Nog a bug in PHP -> bogus
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 11:01:36 2025 UTC