From: Gary Wright Date: 2010-09-25T15:13:17+09:00 Subject: Re: how do i force ruby to release memory On Sep 25, 2010, at 1:20 AM, Walton Hoops wrote: > On 9/24/2010 10:41 PM, Amit Tomar wrote: >> >> but Ryan how do i force it to release memory??? > You don't. You remove the reference by setting @stream=nil, and the > Garbage Collector will release the memory when it gets around to it. > Note there are no guarantees about when the GC will run, or what it will > free when it does, so it's not like you will see the memory drop > immediately when you set @stream to nil, in fact it's very likely that > it won't get run until the interpreter tries to allocate the next chunk > of memory for the next 1G object. > It is also important to realize that the memory will *not* be released back to the OS but instead will just become available for re-use by Ruby. In general there is no way to arrange for Ruby (and most other languages) to return memory to the OS. It is difficult to arrange for a contiguous block of free memory. Live objects tend to be scattered here and there breaking up any contiguous blocks of free memory. If anyone knows of some good examples of language runtimes that *do* manage to return memory to the OS, I'd be curious to hear about them. Gary Wright