zentara schrieb: > Almost, the create/undef must be in the same scope ( block{} ). > This works, however, it can't be relied upon. > > #!/usr/bin/perl -w > use strict; > $| = 1; > print "$$\n"; #top -p $$ > > { > my $string; > for ( 1 .. 100000 ) { > $string .= ( 'x' x 1000 ); > } > print "press enter to release"; > <>; > > undef $string; > print "undefined but still in scope of sub, hit enter\n"; > <>; > # if the variable only goes out of scope. > # you *need* to undef it! > } > > print "ok,out of scope, press enter to exit"; > <>; > __END__ > This is a good example. > > See: > http://www.perlmonks.org?node_id=336883 > > With other data structures, like arrays, there seems to be an internal > algorithm for how much is released back to the system. Huge arrays > may be released , but small ones won't. > Isn't there a switch/option, where it is possible to say: release all variables memory if they are not needed anymore (accepting the performance decrease)? I mean as my second code example shows, that the memory is not really reused, although the exact same size was requested. > One trick is to put your huge data into a thread, and it should be > cleaned up when the thread terminates. > > Don't waste too much time on this, there is no clear cut simple rule, > on what and when things get freed. Just let the system handle it. > Thanks for the hint. > > zentara > > -- Patrick Kirsch
-- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/