php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6333 garbage collection is not being performed on create_function?
Submitted: 2000-08-24 09:57 UTC Modified: 2000-09-07 11:43 UTC
From: ewdafa at ewdafa dot b0rk dot co dot uk Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.0.1pl2 OS: linux-2.2.16
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ewdafa at ewdafa dot b0rk dot co dot uk
New email:
PHP Version: OS:

 

 [2000-08-24 09:57 UTC] ewdafa at ewdafa dot b0rk dot co dot uk
the following code causes PHP to continually eat more and more memory where it should be destroying the old reference for $func.

while(1) {
	$array = array();
	$func = create_function('', "return 0;");
	$array[] = $func;
	$func = 0;
	echo "sleeping for a second.\n";
	sleep(1);
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-07 11:43 UTC] andi@php.net
This isn't a bug but how it works. Each create_function() call creates a new unique function. So obviously if you define zillions in an infinite loop you'll run out of memory.
 [2003-12-26 18:27 UTC] josh at mykoala dot com
It's been said that this is just how the function works, 
but it seems as though destroying allocations for an 
anonymous function when redefining to the same variable 
would be the way to handle it.  Example:

for ($i=0; $i<10; $i++) {
        $echoit = create_function('$wha', 'echo $wha;');
        echo memory_get_usage();
        $echoit(" on iteration: #$i\n");
}

How else can you dynamically modify function or code 
without reloading a script?
 [2004-02-23 19:46 UTC] jon at fuck dot org
create_function() is operating as it should, yes, but there is still no way to delete a function during the execution of a script. for silly things like irc bots it gets handy to be able to rehash your function set on the fly, which is possible, but you lose track of the functions you have created thus far when you redefine your array of hashes.

i suggest a delete_function($foo) that removes the created function from memory and renders the hash in $foo useless.

another useful one would be redefine_function(&$foo, create_function(...)) that shortcuts the delete/create step for us.

this comes in handy for silly things like irc bots, when you have a large set of functions to be rehashed without losing your connection to the server by terminating the script.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC