On Sat, Jan 26, 2013 at 9:52 AM, Nokan Emiro <uzleepito / gmail.com> wrote:
>
>>
>> Any ideas as to a good way or suitable mechanisms to implement this?
>
>
> Just a silly one:  if you seldom use that Hash in the store, you can
> eliminate it.  You could
> still lookup your objects by iterating trough ObjectSpace and find them.
> But this way the
> GC will be able to drop objects if there's no reference to them.  Basically
> what you do here
> the same old stuff:  a trade off between memory and CPU.  You have to decide
> if lookup
> speed is more important than memory footprint or the other way around.
> (...or wait for a
> less silly answer here... :)

I think using WeakReference is even better because ObjectSpace lookup
is slow and does not work in some circumstances (JRuby with specific
settings).

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/weakref/rdoc/index.html

If need by one can always create a special Hash wrapper which converts
from and to WeakReference on insert and retrieval.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/