K
Keith Barr
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
==========================================
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
==========================================