in reply to Re^2: Massive Perl Memory Leak
in thread Massive Perl Memory Leak
The above code is a typical use of local. Internally, it is conceptually equivalent to the following code (shown for the innermost block only). You'd get 5, 6, 5 printed.$foo = 5; sub do_something { print $foo, $/; } sub main { do_something(); { local $foo = 6; do_something(); } do_something(); } main();
{ my $unnamed_backup_of_old_value_of_foo = $foo; $foo = 6; do_something(); $foo = $unnamed_backup_of_old_value_of_foo; }
The actual storage of $foo is the first statement. It is what gets changed whenever you see assignments being done.
This of course can get very big and hairy with a huge hash of data to "backup" and "restore" in the equivalent %unnamed_backup_of_old_value_of_datahash. Also, deleting items from the local hash would not have much bearing, since the whole hash will just get tossed out and restored from the backup.
If you're doing local from multiple threads, well, you can see where your memory is going. Secondly, I can quite easily imagine a race condition where your main shared global hash is getting "restored" in the wrong order, leading to pandemonium.
--
[ e d @ h a l l e y . c c ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Massive Perl Memory Leak
by wagnerc (Sexton) on Jun 11, 2007 at 18:32 UTC | |
by BrowserUk (Patriarch) on Jun 11, 2007 at 19:50 UTC | |
by wagnerc (Sexton) on Jun 13, 2007 at 20:08 UTC |