[Borges-users] Re: and some more on caching

Eric Hodel drbrain at segment7.net
Sun Apr 11 23:36:53 EDT 2004


??????? ???????? (slepnev_v at rambler.ru) wrote:

> Well, it seems I just wrote a StateRegistry that uses WeakRef's, not 
> Weak::.
> 
> I do not attach finalizers to anything, it's too buggy. Instead, I 
> delete references to GC'd objects when I iterate over the cache making 
> a snapshot.
> 
> What do you think? At least it works with my app... SushiNet is still 
> buggy, but it's a SushiNet problem I think.

Clicking on the 'Home' button with this StateRegistry no longer results
in growth beyond about 25M, so I think its much improved.

I'll merge this with the RDoc, and check it in.

> require 'weakref'
> 
> class Borges::StateRegistry

[snip]

>   ##
>   # Returns a snapshot of the current state of all registered
>   # objects.
> 
>   def snapshot
>     snapshot = {}
>     removed = []

This should be wrapped in a Thread.exclusive, since assignment is not
atomic.

>     gcWasDisabled = GC.disable
>     @wrefs.each do |wref|
>       if wref.weakref_alive? then
>         obj = wref.__getobj__

This line gives a bajillion warnings:

./lib/Borges/Utilities/StateRegistry.rb:35: warning: copy_finalizer: descarding old finalizers

(ooh, and that's a typo!)

I'm not sure what to do about that though... because it works.

>         snapshot[obj] = obj.clone
>       else removed<<wref 
>       end
>     end
>     GC.enable unless gcWasDisabled
> 
>     @wrefs = @wrefs-removed
>     return snapshot
>   end
> end

-- 
Eric Hodel - drbrain at segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/borges-users/attachments/20040411/8aa706c3/attachment.bin


More information about the Borges-users mailing list