Re: Memory leak in ruby code



Hi,

Thanks for your replies. I've modified the code a little so that my
string "hello" is not the last statement. And also, it is used in
"puts". Even when it's out of scope, it's not being free.

http://pastie.caboo.se/50041

Jason : Why I'm doin this, frankly speaking, the concept of memory
leaks in ruby code is still not very clear to me. I came across
http://scottstuff.net/blog/articles/2006/08/17/memory-leak-profiling-with-rails
- which checks for common objects within 10 seconds interval. So I
wrote a lil piece of code myself to see if any objects created in a
method call, are getting removed or not when it's out of scope.

I'd like to see if someone can point me to an example of memory leak
in ruby code. Or lemme know how to detect proper memory leaks.

Thanks!
Pratik

On 3/27/07, Rick DeNatale <rick.denatale@xxxxxxxxx> wrote:
On 3/27/07, Jason Roelofs <jameskilton@xxxxxxxxx> wrote:
> So my first question is this: why are you doing this? Ruby's garbage
> collector is perfectly capable of finding and preventing REAL memory leaks.
>
> What you have here is not a memory leak detector, but an "objects have been
> created" detector. "hello" is then obviously caught as a new object created,
> and as Ruby returns the result of the last statement of a method, it is not
> yet out of scope until the program quits, in your case.

There's also the problem that he's trying to detect surviving objects
by comparing object_ids before and after GC, there's no guarantee that
an object_id of a gc'd object won't be reused. Object_id's only need
to be unique among LIVE objects.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/




--
rm -rf / 2>/dev/null - http://null.in

Dont judge those who try and fail, judge those who fail to try..

.



Relevant Pages

  • Re: Memory leak in ruby code
    ... A memory leak comes into existence when some piece of code holds longer onto an instance than necessary / intended. ... the issue I tried to convey is that no instances of class Foo will never be collected because @instances holds on to all of them. ... But I think the OP was looking for memory leaks in Ruby code. ...
    (comp.lang.ruby)
  • Re: Memory leak in ruby code
    ... IMO, that's not a memory leak, that's correct behaviour. ... objects and purposely held on to references to them. ... This shouldn't/can't happen in pure Ruby code. ...
    (comp.lang.ruby)
  • Re: Confusion about Image object and PictureBox usage.
    ... I am not sure if I have a memory leak or not. ... >> scope, as with almost all objects in .NET. ... >> leak is coming from elsewhere, possibly in the code that is converting ... >> JPEG getting converted to a .NET bitmap? ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Psuedo-dynamic allocation?
    ... exist after the code that created them goes out of scope: ... Memory leak! ... home dot pacbell dot net slant earnur slant ...
    (comp.lang.cpp)
  • Re: char*
    ... goes out of scope, not that it is. ... would this cause a memory leak? ... So running foo() 1000 time would create 1000 string literal ... So the second time foo() is called the string literal constructed ...
    (comp.lang.c)

Loading