in reply to Memory Management...

If no persistent reference to the $gxmlFoo's is there, the undef is unnecessary; perl will clean-up my() variables automatically at the end of their scope.

If there is a persistent reference, your =undef's will be The Wrong Thing To Do (TM).

The only case where you would need to do anything like that is where there is a (direct or indirect) circular reference, e.g. my $a; $a = \$a