Please reread what I wrote. I agreed that the memory used
directly by the lexical will not be freed. But I
wanted to clarify that in many cases this doesn't matter
much. For example:
sub foo
{
my $val;
if( @_ ) {
$val= shift;
} else {
undef $val;
}
return $val;
}
foo( "x" x 10_000 );
# 10,000 bytes of memory still tied up
foo()
# those 10,000 bytes now free to be reused
foo( \( "x" x 10_000 ) );
# the few bytes needed to store a reference still tied up,
# but the 10,000 bytes for the string value itself are
# already free to be reused.
Yes, closures never being freed is a bug due to Perl itself
making a circular reference. I believe this has already
been fixed. Your example code should not leak memory
whether you consider it reasonable for that to happen
or not. (:
-
tye
(but my friends call me "Tye")
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|