Tuesday, January 3, 2012

When does Perl 5 reclaim the memory used by a variable?

Perl’s garbage collector uses reference-counting. An internal count of references to any data structure is kept; when the count reaches zero, the memory is reclaimed. Perl does not use mark-and-sweep like Java, so circular memory structures cannot be reclaimed without programmer assistance (ie. a DESTROY method), except at the end of execution.

No comments :