JupiterHost.Net wrote: > I just had a discussion about variables going out of scope (for memory > considerations) > > The idea was presented that variables go out of scope as soon they're > last referenced in a block, I always thought it was when the block ended. >
When a var goes out of scope and when the memory is available to perl again are two different things, and when the memory is available to perl again and when the memory is available on the system are two different things (at least on Unix systems). A variable can be reclaimed by the garbage collector as soon as there is no potential for it to be referenced elsewhere in the application. When the garbage collector will actually get to it is another question. And regardless, the memory will still be available to the same process, so it will not be available to other programs for instance until the program has ended. HTH, http://danconia.org > I was just about to search for this and thought I'd ask to see if anyone > knew offhand... > > > In this example is it A or B? > > I'm thinking 'B' but never heard of 'A' before but I suppose it could be > that way... > > { > my $foo = load_100M_of_data(); > > print $foo; # $foo is using 100M of memeory ± > > # A) $foo is now out of scope (and therefore no longer 100M of > memory) since its not used anywhere after that print() in this block > > # 100 lines of code without any use of $foo > > > } # B) $foo is now out of scope (and therefore no longer using 100M of > memory) > > > I'm thinking its B and and the best way to reclaim the memory in this > case is to undef()ine $foo when its no longer used in the block. > > Any insight would be very interesting no doubt :) > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>