(sorry, I should have continued the previous thread I started, but my
ISP's newsserver crashed or something, so I don't have it).
Anyway, In a prior post today I mentioned that I was using eval in a file
search and that if I repeatedly did this on a large file I eventually ran
out of resources. Soooo.... I added the magic GC.start like so:
##########################################################
i = 0
failed = true
found = false
while true do
i += 1
puts i
rptFile = "CYPsw00695.rpt"
srchStr = "!(/Error Count = [1-9]/ || /Abort/ || /[1-9] error/ ||
/fatal/)"
rpt_h = File.open rptFile
puts "after File.open #{rptFile}" if $DEBUG
puts "srchStr is: #{srchStr}" if $DEBUG
while rpt_h.gets do
#puts "while: #$_" if $DEBUG
if eval srchStr
failed = false
found = true
#puts "FOUND: #$_" if $DEBUG
else
failed = true
puts "FAILED : #$_" if $DEBUG
break
end #if eval
GC.start #<=== this solved the problem
end
rpt_h.close
end
#######################################################
Apparently, the regex's in the srchStr create regex objects during the
eval and those regex objects take a while to get cleared out by garbage
collection and since there are many thousands of lines in the file being
checked, the eval happens thousands of times (once on each line). It may
be that on a larger file, I may need to do the GC.start after some number
of lines in order to avoid running out of space.
Phil