[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000130.002] Odd memory leak
On 31 Jan 2000 07:46:24 GMT, gerti@bitart.com wrote:
>The short program below leaks under various versions of perl and
>on various OS. Am I missing something, or is this a bug in perl?
>
>Thanks!
>
>$x="TST00000";
>while(1)
>{
>	my $handle=$x++;
>	open($handle,'/etc/rc'); # or any other file
>	close($handle);
>}
You're filling up the symbol table with empty symbols (closed
filehandles).  Create anonymous symbols with Symbol instead.
    use Symbol;
    while (1) {
        open(my $handle = gensym, '/etc/rc') or die;
	close $handle;
    }
In 5.6, you'll be able to shorten that to:
    while (1) {
        open my $handle, '/etc/rc'  or die;
	close $handle;
    }
Sarathy
gsar@ActiveState.com
- References to:
- 
gerti@bitart.com
 
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]