I have a Perl script where I maintain a very simple cache using a hash table. I would like to clear the hash once it occupies more than n bytes, to avoid Perl (32-bit) running out of memory and crashing.
I can do a check on the number of keys-value pairs:
if (scalar keys %cache > $maxSize)
{
%cache = ();
}
But is it possible to check the actual memory occupied by the hash?