From: Ron Fox Date: 2008-02-22T19:59:56+09:00 Subject: Re: Newbie Mem Leak Issue Dunno about the memory leak but are you aware that in get_files, you only go one level of sub-directory deep, rather than down the whole depth of the directory tree e.g. (with apologies to the excellent Xwin32 product): if I have: c:\program files\ +--> Starnet +---->xwin32 +-----> xwin32.exe I'll never see xwin32.exe in the list of files? If you want full depth my suggestion is that you recursively call get_files (when it encounters a directory) and then append the results it returns to the original result. Ron. Keith Barr wrote: > I am fairly new to Ruby and a program that I have created seems to have > a memory leak. I have generated a small program which does the basics > of my program that leaks, and the test program also seems to leak. Can > anyone spot the design flaw? > > Any help you can provide is greatly appreciated. > > Thanks, > Keith > > > ================================= > class LeakTest > def initialize > print("initialized\n") > # fill up the standard 8M of space so the leak becomes apparent > faster > str = "0123456789 0123456789 0123456789 0123456789 0123456789 > 0123456789 0123456789 0123456789 0123456789 0123456789 " > @huge_mem = Array.new(1000000, str) > end > > def get_files(pathname) > listing = Array.new > > Dir.glob("#{pathname}/*",0) do |f| > # add the files > listing << f > # now add directories. > if(File.directory?(f)) > returnlist = get_files(f) > returnlist.each {|filename| listing << filename } > end > end > return listing > end > > include GC > def cleanup > printf("cleaning up") > GC.start > 5.times do > print"." > sleep(1) > end > print"\n" > end > > def monitor > listing = get_files("C:/Program Files") > printf("Found %d files\n", listing.length) > 5.times do > print"." > sleep(1) > end > print"\n" > end > end > > lt = LeakTest.new > while true > lt.monitor > lt.cleanup > end > ==========================================