# Re: IO not closed by GC

**URL:** <https://www.ruby-forum.com/t/re-io-not-closed-by-gc/93996>\
**Category:** Ruby\
**Created:** [April 17, 2006, 8:35pm UTC](https://www.ruby-forum.com/t/re-io-not-closed-by-gc/93996 "2006-04-17T20:35:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gennady\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@Gennady\_B](https://www.ruby-forum.com/u/Gennady_B)\
**Post date:** [April 17, 2006, 8:35pm UTC](https://www.ruby-forum.com/t/re-io-not-closed-by-gc/93996/1 "2006-04-17T20:35:55Z")

</div>

Even GC.start does not guarantee that the garbage collection will be  
actually started, it is just a hint after all. And I am not sure that  
even when an IO object is being garbage collected, there will be an  
implicit call to close(). I personally would not expect it as no  
finalizers are installed by default.

So the programmer must take care to write the correct code, short or  
long ;-).

Even if GC.start helped in your case, the overall code would be longer  
(because of calls to GC.start) and work much worse (as GC does a lot  
that you may not need for the moment) than what I have suggested. And  
using blocks with popen is GUARANTEED to close descriptors properly. See  
my point?

By the way, you are welcome.

Gennady.

---

<div class="post-metadata">

**Author:** ![Gennady\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@Gennady\_B](https://www.ruby-forum.com/u/Gennady_B)\
**Post date:** [April 17, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/re-io-not-closed-by-gc/93996/2 "2006-04-17T21:25:30Z")

</div>

I have a question abt this GC stuff, tangential to the challenge  
itself, so million pardons, but I see this in many languages – it’s  
always a suggestion rather than a requirement. Is this just to trip up  
incautious programmers with shallow understanding? Or is it a hook for  
special cases when you want to override that stuff w/custom memory  
mgmt? What’s the benefit? I’ve seen so much use of this type of  
command in bad Java and virtually never seen ppl using it anywhere  
else. I guess I sound kind of aggressive or critical but it’s a common  
decision among language designers so there must be some reason for it.  
(Also apologies for the brevity, I’m on my mobile.)

Giles
