If the process truly is exiting then yes,
the memory will be freed. This isn't a
daemon? And while this does not directly
address the issue of leaking memory but
a couple other observations.
Your foreach loop seems to contain a
useless assignment ($^W=1 would expose
that).