#ruby-lang - Fri 2 Mar 2007 between 01:14 and 01:20

NY Lost Funds



slyphonbut that's with blocks
this is not a block, it's a method that's leaving a handle open
JeanNiBeeOh. okay. I sorta get it.
slyphonagain, it's more of a style question
with my example up there, it's obvious that fp will be closed when the block exits
flowandcrashhey guys, if you could give your opinon on this plz: http://pastie.caboo.se/44120
slyphonso you know the scope of that resource
JeanNiBeeAh I assumes the GC would flag my example for garbage collection at end of method also.
slyphonJeanNiBee: nope
GC doesn't run that frequently
teferiGC is nondeterministic
slyphonand ruby GC is not great
JeanNiBeeOkay so Ruby GC < Java GC (And that aint saying much) lol
teferiJeanNiBee: actually, depending on which VM you're using, some of the java GCs are really good
slyphonJeanNiBee: http://whytheluckystiff.net/articles/theFullyUpturnedBin.html
teferihotspot's is definitely better than ruby's
and jrockit's absolutely blows it away
jrockit is crazy
slyphonbut rubinius and YARV have hybrid-generational GC, no?
teferiYARV has generational?
actionslyphon shrugs
slyphonshrugs
i kind of assumed that while they were implementing a VM, they would improve GC
JeanNiBeeSo, 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' ?
slyphonJeanNiBee: yeah
JeanNiBeeApologise for typos. only get on late when kids are in bed and when I'm tired I lose coordination. ;l)
slyphonJeanNiBee: in your case, it would be theoretically possible to run into "too many open file handles" before GC run
JeanNiBee: np ;)
JeanNiBeeAh, good point.
That Ican handle (Forgot to close many a Db connectin in a finally block of my code before... same situation I guess.
slyphonJeanNiBee: 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
JeanNiBeeNow we're just gone beyond my limited Ruby experience. lol
slyphonheh
well
JeanNiBeeBut I"ll keep that i mind when I get to that chapter on exceptions etc.
:)
slyphonas opposed to File.open() { |fp| fp.each { |line| puts line } }
teferileaking file handles is a bad idea
so, don't do it :P
slyphonFile.open() { |fp| while line = fp.gets; puts line; end }

Page: 2 9 16 23 30 37 44 51 58 

IrcArchive

NY Lost Funds