jettero has asked for the wisdom of the Perl Monks concerning the following question:

As mentioned in my Memory post, I've got a terrible memory leak. I tracked it down to my go_names function. I re-wrote it to use a fork to nslookup instead of Net::DNS.

Did I write go_names like an idiot? Currently I think there might be a memory leak in Net::DNS. Since I think it's pretty widely used I find that unlikely.

I run go_names about 5 times per minute in a daemon that I wrote. After a day or so the rss is up around 27megs! :O

Replies are listed 'Best First'.
Re: Leaks
by chromatic (Archbishop) on Sep 04, 2000 at 06:40 UTC
    If you keep storing (new) information in %name_cache, you'll eventually end up with a huge hash. The rate of growth depends on your cache hit rate. I believe Sriram Srinivasan's Advanced Perl Programming or perlguts gives a pretty good idea of how many bytes of memory each bucket in the hash consumes. (64 bytes sticks out in my mind, but that's just a rough guess and possibly very wrong.)

    I would suggest limiting the number of entries you store. Tie::Cache::LRU or Tie::CacheHash might come in handy there.

      Indeed there is. Install Memoize (ware the joke) and then take a look at Memoize::Expire.

      Actually don't just beware of the joke. Stop and think about what it says for a bit. (That is why it is there after all.) It is actually pretty scary when you think about what you probably just did as root. (Install it if you have no idea what I am talking about.)

      Actually I'm pretty sure it isn't the name cache that's the problem. This function is called with the same 10 or 20 names over and over. Besides, when I re-wrote it there was no memory leak--but I still used the name cache.

      I am going to look at some of the packages you (chromatic) and tilly suggested so far though!

Re: Leaks
by ncw (Friar) on Sep 04, 2000 at 20:45 UTC
    We use Net::DNS to look up several 100,000 names per day. We don't cache them - that is what we run a nameserver for neh ;-)

    It certainly doesn't leak memory otherwise we would have noticed.