Re: Memory leak or expected behavior?

From: zentara (zentara_at_highstream.net)
Date: 12/31/04


Date: Fri, 31 Dec 2004 10:31:10 -0500

On 30 Dec 2004 08:31:59 -0800, syost@quicktopic.com wrote:

>OTOH I do see memory usage as reported by 'ps' grow incrementally in my
>Apache/mod_perl httpd processes (usu. from about 10M to 50M over their
>lifetimes) , so I guess I've got to look for circular references. Or
>maybe there is no leak, but instead the variations in client usage of
>each web page bump the memory out, and as we know it's not given back
>to the OS until the process dies.
>Thanks again. Any other comments welcome.
>
>Steve

My experience with objects 'leaking' memory ( not a true leak, but
it looks like one ) comes from using Tk.

In Tk you need to reuse objects, because it keeps a reference to
all objects internally, so they never go out of scope. So the examples
we were using, would leak if used in Tk. I'm hazarding a guess that
mod_perl is doing the same thing.

In Tk, I reuse objects by first creating a numbered pool of objects
based on the maximum I will need in play at any one time. Then when I'm
done with an object I return it to the queue-pool, ready to be
reconfigured and reused.

For instance if I have a bunch of photos to process, I will make enough
photo objects to handle what will be on-screen at any one time. When
I need to bring up new ones, I don't undef the old objects and create
new ones, I use "configure" on them, to interanlly clear them out and
fill them with fresh data.

This is probably the biggest mistake new Tk programmers run into,
they build apps depending on creating-destroying objects, and never
watch their memory.

So I'm gussing this is what is happening in your mod_perl. Instead
of trying to track down where the hidden reference is( you probably
won't); work on a scheme of reusable objects.

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


Relevant Pages

  • Re: GC.Collect can be trusted?
    ... The problem you are describing is not a real "memory leak", the problem is that you don't know who's keeping a reference to the object, so you aren't able to release the object by setting it's reference to null, this is an application bug disguised as a leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: memory leak in DBI XS bootstrap code
    ... I just ran valgrind with your fix - there seems to still be a leak. ... The trick is to use newSV to alloc memory in the form of an SV ... >> The file called INSTALL in the perl source code directory. ... without telling perl its a reference. ...
    (perl.dbi.users)
  • Re: "Help needed - I dont understand how Python manages memory"
    ... All my investigations on possible memory leaks in Trac have only ... what appears as a leak is an unfortunate side effect of ... but that's not a *reference* leak. ...
    (comp.lang.python)
  • Re: Is garbage collection here yet?
    ... So, objects don't really leak. ... We should just be clear that GC isn't a silver bullet that magically eliminates memory leaks. ... It's very hard to recognise what a reference is in general because the property of being a reference is not inherent but is a property of some interpretation. ... So new forms of reference crop up all the time in applications and so garbage collection is always a best-attempt. ...
    (comp.lang.tcl)
  • [RFC] page replacement requirements
    ... Submitting too much I/O at once can kill latency and even lead to deadlocks when bounce buffers are involved. ... Must be able to deal with multiple memory zones efficiently. ... When on completion of the write to their backing-store the reference bit is still unset a callback is invoked to place them so that they are immediate candidates for reclaim again. ... For traditional page replacement algorithms this is not a big issue since we just implement per zone page replacement; ...
    (Linux-Kernel)