forked from headius/weakling
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README and remove the hash attr on WeakRef::IdHash.
- Loading branch information
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,3 @@ | |
|
||
puts "all items in weak id hash:" | ||
ids.each {|i| puts "#{i} = #{wh[i]}"} | ||
puts "hash size: #{wh.hash.size}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters