| slyphon | but that's with blocks this is not a block, it's a method that's leaving a handle open |
| JeanNiBee | Oh. okay. I sorta get it. |
| slyphon | again, it's more of a style question with my example up there, it's obvious that fp will be closed when the block exits |
| flowandcrash | hey guys, if you could give your opinon on this plz: http://pastie.caboo.se/44120 |
| slyphon | so you know the scope of that resource |
| JeanNiBee | Ah I assumes the GC would flag my example for garbage collection at end of method also. |
| slyphon | JeanNiBee: nope GC doesn't run that frequently |
| teferi | GC is nondeterministic |
| slyphon | and ruby GC is not great |
| JeanNiBee | Okay so Ruby GC < Java GC (And that aint saying much) lol |
| teferi | JeanNiBee: actually, depending on which VM you're using, some of the java GCs are really good |
| slyphon | JeanNiBee: http://whytheluckystiff.net/articles/theFullyUpturnedBin.html |
| teferi | hotspot's is definitely better than ruby's and jrockit's absolutely blows it away jrockit is crazy |
| slyphon | but rubinius and YARV have hybrid-generational GC, no? |
| teferi | YARV has generational? |
| action | slyphon shrugs |
| slyphon | shrugs i kind of assumed that while they were implementing a VM, they would improve GC |
| JeanNiBee | So, in a nutshell in methods it's better / safer / cleaner code to play withth ehandle returned by the static methods for resrouces.. and pass those handle into block to ensure they are cleaned up when we reach the end of their scope? Is that a valid 'summary' ? |
| slyphon | JeanNiBee: yeah |
| JeanNiBee | Apologise for typos. only get on late when kids are in bed and when I'm tired I lose coordination. ;l) |
| slyphon | JeanNiBee: in your case, it would be theoretically possible to run into "too many open file handles" before GC run JeanNiBee: np ;) |
| JeanNiBee | Ah, good point. That Ican handle (Forgot to close many a Db connectin in a finally block of my code before... same situation I guess. |
| slyphon | JeanNiBee: there is a counter though to using blocks, as they incur extra stack creation, so in a tight loop, it's sometimes more performant to use the non-block form with an 'ensure' clause |
| JeanNiBee | Now we're just gone beyond my limited Ruby experience. lol |
| slyphon | heh well |
| JeanNiBee | But I"ll keep that i mind when I get to that chapter on exceptions etc. :) |
| slyphon | as opposed to File.open() { |fp| fp.each { |line| puts line } } |
| teferi | leaking file handles is a bad idea so, don't do it :P |
| slyphon | File.open() { |fp| while line = fp.gets; puts line; end } |