# Interesting GC.start

**URL:** <https://www.ruby-forum.com/t/interesting-gc-start/178177>\
**Category:** Ruby\
**Created:** [October 30, 2009, 8:03am UTC](https://www.ruby-forum.com/t/interesting-gc-start/178177 "2009-10-30T08:03:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [October 30, 2009, 8:03am UTC](https://www.ruby-forum.com/t/interesting-gc-start/178177/1 "2009-10-30T08:03:16Z")

</div>

# irb: name='1’_1024_1024\*100;nil # 100m name=rand GC.start

$ ps -ef|grep irb  
ax 14081 13958 0 14:57 pts/2 00:00:00 irb

# $ top 14081

## 14081 ax 20 0 114m 112m 1960 S 0 11.3 0:00.66 irb 14081 ax 20 0 13824 11m 1960 S 0 1.2 0:00.54 irb

when “name=rand;GC.start”, 112m-\>11m,why?

but “name=nil;GC.start”,dont work

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [October 30, 2009, 2:01pm UTC](https://www.ruby-forum.com/t/interesting-gc-start/178177/2 "2009-10-30T14:01:46Z")

</div>

2009/10/30 Haoqi H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ## 14081 ax 20 0 114m 112m 1960 S 0 11.3 0:00.66 irb 14081 ax 20 0 13824 11m 1960 S 0 1.2 0:00.54 irb
> 
> when “name=rand;GC.start”, 112m-\>11m,why?

Because the large string is eligible for collection.

> but “name=nil;GC.start”,dont work

What do you mean? If “name=nil” does not work you should probably  
recompile your Ruby interpreter from the sources.

If you mean that you then do not observe a memory drop the reason is  
that although the large string is eligible for collection there is no  
guarantee when it will be collected. That’s how automatic GC works -  
and is supposed to work.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [October 30, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/interesting-gc-start/178177/3 "2009-10-30T14:44:48Z")

</div>

> > but “name=nil;GC.start”,dont work

> If you mean that you then do not observe a memory drop the reason is  
> that although the large string is eligible for collection there is no  
> guarantee when it will be collected. That’s how automatic GC works -  
> and is supposed to work.
> 
> Cheers
> 
> robert  
> “name=nil;GC.start” dont work:  
> I mean that then do not observe a memory drop.  
> And “name=‘1’\*1;GC.start” it also works(observer a memory drop)

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [October 31, 2009, 11:04pm UTC](https://www.ruby-forum.com/t/interesting-gc-start/178177/4 "2009-10-31T23:04:12Z")

</div>

Haoqi H. wrote:

> # irb: name='1’_1024_1024\*100;nil # 100m name=rand GC.start

…

> when “name=rand;GC.start”, 112m-\>11m,why?
> 
> but “name=nil;GC.start”,dont work

GC is tricky, because depending on what method calls, “ghost” references  
to the original name might still exist on the stack.  
You could try it with jruby/REE/1.9 to see if one of them works better,  
but in this instance it appears that running “some methods” clears the  
stack while others leave it dirty.  
-r
