From: Logan Capaldo Date: 2005-07-14T06:50:05+09:00 Subject: Re: How do I reduce the memory usage of a script? On Jul 13, 2005, at 5:30 PM, Scott Ellsworth wrote: > Hi, all. > > Please find attached a simple Ruby script that rummages through my > ITunes files, reads the first megabyte or so, finds the encoder, and > then prints the encoder and filename. This lets me know which tracks > need re-ripping. > > This script blows through half a gig of RAM while running, and I > really > do not see why. It should only have perhaps a few megabytes at max in > RAM. > > FWIW, the output looks like: > iTunes v4.9, QuickTime 7.0.1 /Users/work/Music/iTunes/iTunes > Music/Yellowcard/Ocean Avenue Song1.m4a > iTunes v4.9, QuickTime 7.0.1 /Users/work/Music/iTunes/iTunes > Music/Yellowcard/Ocean Avenue Song2.m4a > iTunes v4.9, QuickTime 7.0.1 /Users/work/Music/iTunes/iTunes > Music/Yellowcard/Ocean Avenue Song3.m4a > > Style and speed optimizations are accepted, but the runtime is under a > minute now for the 5500 files I have in my library, so memory usage is > my real problem. > > Help? > > #!/usr/bin/env ruby > require 'find' > def procpath(f) > if File.file?(f) then > if File.fnmatch("*.m4a",f) then > found = false > data = IO.read(f, 65536*8) > re = /[[:alnum:]_., ]{9,}/ > data.scan(re) do |string| > if (string =~ /QuickTime/) then > filename = File.basename(f) > dirname = File.dirname(f) > # puts "#{string} #{dirname}" > puts "#{string} #{dirname} #{filename}" > found = true > break > end > end > if (!found) then > puts "Unknown #{f}" > end > end > elsif File.directory?(f) && !File.fnmatch(".", f) && > !File.fnmatch("..", f) then > Dir.foreach(f) { |subf| procpath(subf) } > end > end > > Find.find("/Users/work/Music/iTunes/iTunes Music/") do |f| > procpath(f) > end > > Scott > -- > scott@alodar.nospam.com > Java, Cocoa, and Database consulting for the life sciences > > -- > Scott Ellsworth > scott@alodar.nospam.com > Java and database consulting for the life sciences > > Well mileage may vary and all that jazz, but on my box it took up like ~30M virtual according to top and like 1.5MB ~ 2MB physical. Have you tried explicity invoking the GC?