php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36197 php does not free script memory when the process alive
Submitted: 2006-01-29 09:08 UTC Modified: 2006-02-05 18:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: momo@php.net Assigned:
Status: Not a bug Package: Apache related
PHP Version: 5.1.2 OS: gentoo 2005.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: momo@php.net
New email:
PHP Version: OS:

 

 [2006-01-29 09:08 UTC] momo@php.net
Description:
------------
while playing with big arrays, i see that memory that was used on php with apache 1.3 sapi doesn't became free till the next time apache use *the same* process. here how the memory looks like *after* the scripts have finish to run:

momo@(none) htdocs # ps -A v|grep http
27677 ?        Ss     0:00      0  4188  8875  4532  0.8 /www5/bin/httpd
27679 ?        S      0:00      0  4188  8875  3072  0.5 /www5/bin/httpd
27680 ?        S      0:03      1  4188 31759 26580  5.1 /www5/bin/httpd
27681 ?        S      0:00      0  4188 54019 48740  9.4 /www5/bin/httpd
27682 ?        S      0:00      0  4188  8875  2532  0.4 /www5/bin/httpd
27683 ?        S      0:00      0  4188  8875  2536  0.4 /www5/bin/httpd
27716 ?        S      0:00      0  4188  8875  2536  0.4 /www5/bin/httpd
27764 pts/0    R+     0:00      0    57  1406   436  0.0 grep http


Reproduce code:
---------------
for($a=0;$a<1024*512;$a++) {
	$ret[] = 1.1;
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-29 16:07 UTC] sniper@php.net
Expected behaviour. Search more information how memory allocation and freeing works in Linux from the web..and also 'man ps'
 [2006-01-30 12:24 UTC] momo@php.net
My apology of being nagger but the bellow code, use memory (even without inner free) that become free right after the script execution ending. is there a problem to get back the php varibles memory, just like the efree do?

PHP_FUNCTION(momo_test)
{
        char *some_memory;
	int a;
	
	some_memory = (char *) emalloc(0x4000000);
	for(a=0;a<0x4000000;a++) some_memory[a]=0;
	//efree(some_memory);
}

Can you send me more exact reference how the linux memory allocation responsible for this spend memory?
 [2006-01-31 16:12 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP uses an internal memory memory manager, when you allocate memory using emalloc() it'll be freed at the end of the request, even if you don't free it explicitly yourself.
 [2006-02-02 09:19 UTC] momo@php.net
Thank for the replay, but please read my question carefully.
I know that php free the allocated by emalloc memory on the end of script, my question was why php don't do it for the memory that was allocated by the *php end user* just like the example i give above.

Yes you can call it feature, and blame linux mm, but the fact that php do it for the memory used by the extensions developers, give me a hint that may there is simple way protecting the end user to not kill his server as well, especially when we talk about linux+apache 1.3.x that AFAIK it the most common configuration of production php web servers.

(sorry for opening the bug again, if you will change the status of the bug to 'will not fix', i'll let him die)
 [2006-02-02 15:05 UTC] iliaa@php.net
if you want to restrict memory usage use the memory-limit configuration option when compiling PHP.
 [2006-02-02 15:21 UTC] momo@php.net
Good answer to another question.

No, i don't won't to restrict the memory usage. i want use huge arrays and i also want the php to free the memory it use on the end of script.

If that is not possible for some reason, please mark this bug as "won't fix" not bogus.
 [2006-02-05 18:01 UTC] iliaa@php.net
Once PHP frees memory it is now up to the OS to make this memory available to other process. Memory managers on some OSes like Linux try to anticipate future use of memory by the same process and do not immidiately make the memory available. This however is no fault of PHP, nor is something PHP can do anything about.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 16:01:29 2024 UTC