in reply to Garbage collection at subroutine return

That function has no side effects (aside from taking a long time and a lot of memory) and it returns nothing. The following equivalent function is a lot faster:
sub DoIt { return; }

If this is not what you want you'll have to explain what you want in a bit more detail.