[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to free an unused object forcefully?

Ochronus

11/23/2007 9:55:00 AM

Hi All,

I have a script which serves as a cache, storing "large" (around
60MB) objects. Once in a day I have to drop
the old data and load fresh data in the cache. The cache itself is
simply a hash of hashes, nothing special. I thought of a simple
process: I wrote a loader method,

def loader
tmp_holder = get_new_data(somehow)
$actual_cache = tmp_holder
end

I expected tmp_holder to be freed after the method finishes, since
it's not referred to anywhere else. What's actually
happening is that my script is using more and more memory as days
pass, as if tmp_holder was still present.
How could I solve this situation?

Thank you in advance,
Ochronus
1 Answer

Bira

12/2/2007 3:19:00 PM

0

On Nov 23, 2007 8:00 AM, ochronus@gmail.com <ochronus@gmail.com> wrote:
> Hi All,
>
> I have a script which serves as a cache, storing "large" (around
> 60MB) objects. Once in a day I have to drop
> the old data and load fresh data in the cache. The cache itself is
> simply a hash of hashes, nothing special. I thought of a simple
> process: I wrote a loader method,
>
> def loader
> tmp_holder = get_new_data(somehow)
> $actual_cache = tmp_holder
> end
>
> I expected tmp_holder to be freed after the method finishes, since
> it's not referred to anywhere else. What's actually
> happening is that my script is using more and more memory as days
> pass, as if tmp_holder was still present.
> How could I solve this situation?

tmp_holder is still being referenced, since you're assigning it to
that global variable.

The example below seems to be more GC-friendly to me, but since I'm
not exactly an expert at this, I may be wrong. But it might be worth
trying:

$actual_cache.clear
$actual_cache.merge(get_new_data(somehow))



--
Bira
http://compexplicita.bl...
http://sinfoniaferida.bl...