# Memory management in long running scripts

**URL:** <https://www.ruby-forum.com/t/memory-management-in-long-running-scripts/123600>\
**Category:** Rails\
**Created:** [December 19, 2007, 1:56am UTC](https://www.ruby-forum.com/t/memory-management-in-long-running-scripts/123600 "2007-12-19T01:56:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@simon1](https://www.ruby-forum.com/u/simon1)\
**Post date:** [December 19, 2007, 1:56am UTC](https://www.ruby-forum.com/t/memory-management-in-long-running-scripts/123600/1 "2007-12-19T01:56:24Z")

</div>

Hi,

I have a script that runs for a long time, and seems to use up a large  
chunk of memory, building up fairly quickly, but then never really  
going above 55% of the system memory. This is the basic structure of  
my script:

loop do  
Find.find(path) do |name|  
if FileTest.directory? name  
Find.prune unless name.eql? path  
else  
do\_something\_with\_file  
end  
end  
sleep(0.05)  
end

Even when my do\_something\_with\_file function is modified to simply  
return right away, the memory usage of the script continues to  
increase. Is there any issue with reading directories as I am above?  
Or is there a way to cap the amount of memory a script uses, or a way  
to force garbage collection?

Thanks,

Simon
