Having had your problem just one week ago:
production software consuming memory allocated for an array inside a for loop,
I've searched PM and read the threads on it.
Do a search on "undef array" to see what I (might) have found then.
In short and as a rule of thumb:
- @array = (); # free the memory allocated for the contents of the array. Frees less than 90% of the memory.
- undef @array; # as above and free the memory used for the index of the array. Frees nearly 100% of it.
I was also asked to test on different behaviour in past Perl versions when freeing memory in arrays. I didn't encounter anything funny from 5.0005_04 through the 5.6es towards 5.8.5.
I used Devel::Size for the perl data and unix's ps command to look at the overall size of the process. The latter produced nothing unexpected: As the array grows, so does the size of the programme in the perl interpreter.
You can't return the used memory to the OS, if that's what you are looking for. If that's your concern, consider forking a child that will later consume that much memory, and die, freeing the memory then.
Cheers, Sören
|