in reply to How clever is the garbage collector?

The formatting of your code is kind of tough to get through, but if I understand correctly you are essentially creating a data structure that looks like this:

$sq = bless({ BB => [ { 'some hash' => 'number 1' }, { 'some hash' => 'number 2' }, { 'some hash' => 'number ...' }, { 'some hash' => 'number 1_000_000' }, ], }, 'TestSequence');

And the question is whether running delete( $sq->{BB} ) will cause the garbage collector to trash all of the hashes. The answer is yes, assuming the program doesn't contain any other references to those hashes (including the hashes referencing each other), then the garbage collector will get them all.

However, you should keep in mind that having the garbage collector destroy those objects will not necessarily cause your program to release the memory they consumed, but that is a different question which has been answered before (several times).


We're not surrounded, we're in a target-rich environment!