W3cubDocs

/Crystal 0.31

class WeakRef(T)

Overview

Weak Reference class that allows a referenced object to be garbage-collected.

require "weak_ref"

ref = WeakRef.new("oof".reverse)
p ref.value # => "foo"
GC.collect
p ref.value # => nil

Defined in:

weak_ref.cr

Constructors

Instance Method Summary

  • #value

    Returns the referenced object or Nil if it has been garbage-collected.

Constructor Detail

def self.new(target : T)Source

Instance Method Detail

def valueSource

Returns the referenced object or Nil if it has been garbage-collected.

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/WeakRef.html