Memory leak

one of my ruby apps has a memory leak. Ive looked through the code and
cant find it.

I have about 6000 lines (so please dont ask me to post the code) using
FX ruby and 10 or so classes I have written.

Im able to switch the gui off and run, but the memory leak still
happens, so its not FX or my gui code.

The app starts at around 15M, and increases to about 100M after 3
days.

This is using ruby 1.8.1 (2004-01-27) [i386-mswin32] from the Windows
installer. It happens on both XP and W2k

I think I may be able to run the suspect code outside of the main app,
so Im going to try that now.

Can any one give me any ideas on how to find the leak?

Thanks

Paul

If you were on linux I'd suggest using valgrind, but since you are
running windows that won't work. There are plenty of other good memory
leak detection tools out there; throw "memory leak detection" at google
and you'll come up with a few good hits.

Paul

···

On Tue, Jun 08, 2004 at 01:33:37AM +0900, Paul wrote:

Can any one give me any ideas on how to find the leak?

Paul wrote:

one of my ruby apps has a memory leak. Ive looked through the code and
cant find it.

I have about 6000 lines (so please dont ask me to post the code) using
FX ruby and 10 or so classes I have written.

Im able to switch the gui off and run, but the memory leak still
happens, so its not FX or my gui code.

The app starts at around 15M, and increases to about 100M after 3
days.

This is using ruby 1.8.1 (2004-01-27) [i386-mswin32] from the Windows
installer. It happens on both XP and W2k

I think I may be able to run the suspect code outside of the main app,
so Im going to try that now.

Can any one give me any ideas on how to find the leak?

Keep chopping down the code, and try to find a minimal reproducible case? That may be hard if it takes days to tell if the leak is happening.

Do you know whether this is a true memory leak (allocated memory that is unreachable) or just objects that are piling up somewhere (reachable but unused). You might be able to detect this using ObjectSpace.each_object. It would at least tell you if the number of objects is growing, but it wouldn't tell you if resizable objects (arrays, strings, etc.) were growing.

What I've wished for before was ObjectSpace.memory_allocated, which would tell you how much memory the ruby memory manager knows about and would answer this question directly.

looking at a 210Mb Ruby process now myself (1.8.1 Linux),
how does the Ruby gc reclaim memory anyway?

Does the Ruby gc
a) defragment memory and mem use always shrinks down to used
   size after some gc iterations or
b) mem grows and if mem gets freed only in small pieces and never free
   in large pieces only holes get filled by newer allocations

I suspect a case of b, as ObjectSpace count goes down by 140000 (~10% of
ObjectSpace count) but "ps" mem usage doesn't :-/

Martin

···

Paul <paul.rogers@shaw.ca> wrote:

The app starts at around 15M, and increases to about 100M after 3
days.

Something I've found useful in the past was to use ObjectSpace to create a histogram of counts of extant objects by class. I take a snapshot, run for a while, take another, and so on. If one particular class of object shows an increasing number of objects, then I can focus in to see if I'm keeping references that I shouldn't.

Cheers

Dave

···

On Jun 7, 2004, at 14:02, Joel VanderWerf wrote:

Do you know whether this is a true memory leak (allocated memory that is unreachable) or just objects that are piling up somewhere (reachable but unused). You might be able to detect this using ObjectSpace.each_object. It would at least tell you if the number of objects is growing, but it wouldn't tell you if resizable objects (arrays, strings, etc.) were growing.

I remember a message some time ago about using valgrind with ruby.
Someone was asking for a suppression file to avoid false results, if
there are info about that maybe we should have them on the wiki ?

···

il Tue, 8 Jun 2004 02:20:38 +0900, Paul Brannan <pbrannan@atdesk.com> ha scritto::

On Tue, Jun 08, 2004 at 01:33:37AM +0900, Paul wrote:

Can any one give me any ideas on how to find the leak?

If you were on linux I'd suggest using valgrind,

Hi,

···

In message "Re: memory leak" on 04/06/09, Martin Pirker <crf@sbox.tu-graz.ac.at> writes:

Does the Ruby gc
a) defragment memory and mem use always shrinks down to used
  size after some gc iterations or
b) mem grows and if mem gets freed only in small pieces and never free
  in large pieces only holes get filled by newer allocations

Ruby uses conservative garbage collection that never do any type of
page compaction. Ruby GC frees allocated heap pages only when all
objects in the page are recycled.

              matz.

-->> What I've wished for before was ObjectSpace.memory_allocated, which
would tell you how much memory the ruby memory manager knows about and
would answer this question directly.

This is what I was hoping for :frowning:

Still, the answers about object space will help

Thanks for all the help.

Paul