memory leak

P

Paul

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
 
P

Paul Brannan

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

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
 
J

Joel VanderWerf

Paul said:
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.
 
G

gabriele renzi

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

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 ?
 
D

Dave Thomas

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.

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
 
P

Paul

-->> 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 :-(

Still, the answers about object space will help

Thanks for all the help.

Paul
 
M

Martin Pirker

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

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: memory leak"

|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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FFI Memory Leak 4
Find memory leak in 1.9 app 5
newbie question regarding memory leak 4
Memory leak 8
memory leak 26
Memory Leak Madness 18
mysql gem memory leak 1
Memory Leak (again) 3

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top