# (fwd) \[Borges-users\] memory strikes back!

**URL:** <https://rubytalk.org/t/fwd-borges-users-memory-strikes-back/11456>\
**Category:** ruby-talk\
**Created:** [10 May 2004 18:47 UTC](https://rubytalk.org/t/fwd-borges-users-memory-strikes-back/11456 "2004-05-10T18:47:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![George5](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@George5](https://rubytalk.org/u/George5)\
**Post date:** [10 May 2004 18:47 UTC](https://rubytalk.org/t/fwd-borges-users-memory-strikes-back/11456/1 "2004-05-10T18:47:00Z")

</div>

Can anyone of the Ruby experts tell us where the memory leak might be?

> **···**
>
> — forwarded message —
> 
> Hi,
> 
> about the ol’ Borges memory problem: there’s a small but nonzero  
> possibility that continuations+objects+weakrefs are a bad combination  
> in Ruby, after all. Here’s a small test I just wrote. I let it grow to  
> about 70 megs on my system before shutting it down… although it’s  
> obvious from the code that memory should be bounded.
> 
> require ‘weakref’
> 
> class A  
> attr\_accessor :child
> 
> ```
> def foo
> @child = B.new
> @child.call
> end
> 
> ```
> 
> end
> 
> class B  
> def call  
> callcc do |cc|  
> @cont = cc  
> end  
> end
> 
> ```
> def answer(obj)
> @cont.call(obj)
> end
> 
> ```
> 
> end
> 
> def purge(array)  
> array.delete\_if {|x| not x.weakref\_alive?}  
> end
> 
> a = A.new  
> arr = []  
> loop { a.foo; arr \<\< WeakRef.new(a.child); purge(arr)}
> 
> Funny thing is: if we remove the weakref array thing, memory is  
> bounded; and if we don’t save the continuation, memory is bounded too.  
> Maybe I’m mistaken somewhere. Actually I hope I’m mistaken. Somebody  
> correct me.
> 
> Vladimir Slepnev

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [18 May 2004 23:10 UTC](https://rubytalk.org/t/fwd-borges-users-memory-strikes-back/11456/2 "2004-05-18T23:10:14Z")

</div>

Hi,

> **···**
>
> In message “(fwd) [Borges-users] memory strikes back!” on 04/05/11, Michael Neumann [mneumann@ntecs.de](mailto:mneumann@ntecs.de) writes:
> 
> > Can anyone of the Ruby experts tell us where the memory leak might be?
> 
> Ruby uses conservative garbage collection, which scans C stack and  
> considers the value suspicious to be a pointer as a pointer. In this  
> case, perhaps, some unused junk saved in the stack copy in the  
> continuation object refers to the object, which is a target of a  
> weakref. I will try something, but it’s hard to promise to fix.
> 
> ```
> matz.
> 
> ```
