Skip to content

Commit

Permalink
Add README and remove the hash attr on WeakRef::IdHash.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 12, 2010
1 parent c058555 commit ea632b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
43 changes: 43 additions & 0 deletions README.txt
@@ -0,0 +1,43 @@
weakling: a collection of weakref utilities for Ruby

== Summary ==

This library provides:

* a modified WeakRef implementation for JRuby that supports a reference queue
* a WeakRef::RefQueue class
* a weak-valued ID map to replace typical uses of _id2ref

In the future it may provide additional features like a generic WeakHash or other
reference types like soft and phantom references.

== Usage ==

Just require 'weakling'. It will require 'weakref' along with the refqueue JRuby
extension and the weakling/collections library containing the weak id hash.

== Example ==

require 'weakling'

wh = WeakRef::IdHash.new

ary = (1..10).to_a.map {Object.new}
ids = ary.map {|o| wh.add(o)}

puts "all items in weak_id_hash:"
ids.each {|i| puts "#{i} = #{wh[i]}"}

puts "dereferencing objects"
ary = nil

puts "forcing GC"
begin
require 'java'
java.lang.System.gc
rescue
GC.start
end

puts "all items in weak id hash:"
ids.each {|i| puts "#{i} = #{wh[i]}"}
1 change: 0 additions & 1 deletion examples/id_hash.rb
Expand Up @@ -21,4 +21,3 @@

puts "all items in weak id hash:"
ids.each {|i| puts "#{i} = #{wh[i]}"}
puts "hash size: #{wh.hash.size}"
2 changes: 0 additions & 2 deletions lib/weakling/collections.rb
Expand Up @@ -2,8 +2,6 @@
require 'refqueue'

class WeakRef::IdHash
attr_accessor :hash

def initialize
@hash = Hash.new
@queue = WeakRef::RefQueue.new
Expand Down

0 comments on commit ea632b9

Please sign in to comment.