[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

GC error ?

Piotr Sawicki

2/16/2008 12:13:00 PM

Run this program and observe memory usage.

<code>

def leaker
a = ""
10000.times do
a = a + "buble"
end
a = ""
end


loop do
leaker
end

</code>
--
Posted via http://www.ruby-....

18 Answers

Robert Klemme

2/16/2008 1:32:00 PM

0

On 16.02.2008 13:12, Piotr Sawicki wrote:
> Run this program and observe memory usage.
>
> <code>
>
> def leaker
> a = ""
> 10000.times do
> a = a + "buble"
> end
> a = ""
> end
>
>
> loop do
> leaker
> end
>
> </code>

Your point being?

robert

Piotr Sawicki

2/16/2008 5:40:00 PM

0

Robert Klemme wrote:
> Your point being?
>
> robert

I run this on ruby-1.8.6 (Linux and cygwin [WinXP]).
Why memory used by ruby process grow?
Is that normal behaviour ?

I wrote the same progam on python and perl and I have discover that that
this problem occur only in ruby.




--
Posted via http://www.ruby-....

Gary Wright

2/16/2008 8:28:00 PM

0


On Feb 16, 2008, at 12:39 PM, Piotr Sawicki wrote:

> Robert Klemme wrote:
>> Your point being?
>>
>> robert
>
> I run this on ruby-1.8.6 (Linux and cygwin [WinXP]).
> Why memory used by ruby process grow?
> Is that normal behaviour ?

I ran that code via irb and compared the memory usage to running
'loop {}' in irb.

Your code used more memory but it oscillated around a fixed point
that was about 10 megabytes larger than the empty loop process, it
didn't grow.

This was on Mac OS X 10.4, ruby 1.8.6.


Radoslaw Bulat

2/17/2008 12:33:00 AM

0

R3V5cywgaXQncyB3b3J0aCB0byBzZW5kIGl0IHRvIHJ1YnktY29yZSBhbmQgYXNrIHRoZXJlLiBJ
IGNoZWNrZWQKcnVieTEuOSBhbmQgaXQgaGFzIHRoZSBzYW1lIGlzc3VlIDovLgoKCgotLSAKUmFk
b3OzYXcgQnWzYXQKCmh0dHA6Ly9yYWRhcmVrLmpvZ2dlci5wbCAtIG3zaiBibG9nCg==

Robert Klemme

2/18/2008 8:40:00 AM

0

2008/2/16, Piotr Sawicki <piotr.sawicki@gmail.com>:
> Robert Klemme wrote:
> > Your point being?
>
> I run this on ruby-1.8.6 (Linux and cygwin [WinXP]).
> Why memory used by ruby process grow?
> Is that normal behaviour ?
>
> I wrote the same progam on python and perl and I have discover that that
> this problem occur only in ruby.

Well, concluding from the postings not all versions of Ruby on all
platforms suffer this phenomenon. As far as I can see so far you have
proven that

(1) on cygwin on Windows XP and on Linux
(2) Ruby version 1.8.6
(3) will allocate and free memory in a way that
(4) the OS shows continuous increasing size of used memory
(5) for a particular program, namely one that allocates memory at a high rate.

Whether that's a bug or not is probably really a question for ruby
core. There might be multiple causes for this observed behavior
including but not limited to Ruby's GC.

Kind regards

robert


--
use.inject do |as, often| as.you_can - without end

Piotr Sawicki

2/18/2008 11:44:00 AM

0

I have simple, but ugly solution for this problem.

class String
alias plus +
def +(a)
res = self.plus(a)
GC.start
return res
end
end
--
Posted via http://www.ruby-....

Robert Klemme

2/18/2008 11:50:00 AM

0

2008/2/18, Piotr Sawicki <piotr.sawicki@gmail.com>:
> I have simple, but ugly solution for this problem.
>
> class String
> alias plus +
> def +(a)
> res = self.plus(a)
> GC.start
> return res
> end
> end

That's not a solution. That's a bad workaround which might degrade
performance of other applications.

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

Justin Collins

2/18/2008 11:17:00 PM

0

Piotr Sawicki wrote:
> I have simple, but ugly solution for this problem.
>
> class String
> alias plus +
> def +(a)
> res = self.plus(a)
> GC.start
> return res
> end
> end
>


Obviously this is a just an example to illustrate the issue, but

def leaker
a = ""
10000.times do
a << "buble"
end
a = ""
end


loop do
leaker
end


does not exhibit the same memory usage as the OP.

-Justin

Christopher Dicely

2/19/2008 12:13:00 AM

0

To perhaps underscore Robert's point, I did this in IRB on the OCI
version on WinXP, and its behavior appeared (just watching memory
usage in the Windows task manager) very similar to the with-gc variant
on cygwin, even though it was run without explicit GC calls.
(Interestingly, about 27 MB of the excess over what IRB was using
before running this remained in use afterward until an explicit
GC.start, and the explicit call to GC only dropped that by about 21
MB.)

On Feb 18, 2008 12:40 AM, Robert Klemme <shortcutter@googlemail.com> wrote:
> 2008/2/16, Piotr Sawicki <piotr.sawicki@gmail.com>:
> > Robert Klemme wrote:
> > > Your point being?
> >
> > I run this on ruby-1.8.6 (Linux and cygwin [WinXP]).
> > Why memory used by ruby process grow?
> > Is that normal behaviour ?
> >
> > I wrote the same progam on python and perl and I have discover that that
> > this problem occur only in ruby.
>
> Well, concluding from the postings not all versions of Ruby on all
> platforms suffer this phenomenon. As far as I can see so far you have
> proven that
>
> (1) on cygwin on Windows XP and on Linux
> (2) Ruby version 1.8.6
> (3) will allocate and free memory in a way that
> (4) the OS shows continuous increasing size of used memory
> (5) for a particular program, namely one that allocates memory at a high rate.
>
> Whether that's a bug or not is probably really a question for ruby
> core. There might be multiple causes for this observed behavior
> including but not limited to Ruby's GC.
>
> Kind regards
>
> robert
>
>
> --
> use.inject do |as, often| as.you_can - without end
>
>

Evan Webb

2/19/2008 8:00:00 AM

0

On Feb 16, 4:12 am, Piotr Sawicki <piotr.sawi...@gmail.com> wrote:
> Run this program and observe memory usage.
>
> <code>
>
> def leaker
>     a = ""
>     10000.times do
>          a = a + "buble"
>     end
>     a = ""
> end
>
> loop do
>     leaker
> end
>
> </code>
> --
> Posted viahttp://www.ruby-....

Not a bug in any way. It's simply that the garbage collector has not
been trigger. It runs only when it needs to. As you realized you, you
can force it to run by doing 'GC.start'. If you run 'GC.start' at the
end of your program, you'll see the memory reclaimed.

This is a typical behavior for a mark/sweep garbage collector. Perl
and Python are reference count, freeing memory the instant it goes out
of scope. Ruby waits to free memory until it needs memory to free some.