Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A modified WeakRef impl for JRuby plus some weakref-related tools

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 ext Remove unused import. March 22, 2010
Octocat-spinner-32 lib
Octocat-spinner-32 nbproject
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore Add NB project files. March 22, 2010
Octocat-spinner-32 HISTORY.txt
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 weakling.gemspec
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.

The weakling repository is at

== Usage ==

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

== RefQueue Example ==

require 'weakling'
require 'java'

q =
wr =, q)
puts "weakref object: #{wr.__id__}"

puts "running GC"

puts "weakref alive?: #{wr.weakref_alive?}"
puts "weakref object from queue: #{q.poll.__id__}"

== WeakRef::IdHash Example ==

require 'weakling'
wh =
ary = (1..10) {}
ids = {|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"
  require 'java'
puts "all items in weak id hash:"
ids.each {|i| puts "#{i} = #{wh[i]}"}
Something went wrong with that request. Please try again.