How to free an unused object forcefully?

O

ochronus

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
 
B

Bira

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))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,271
Messages
2,571,361
Members
48,044
Latest member
elitecorp

Latest Threads

Top