Skip to content

Commit

Permalink
Document WeakRef
Browse files Browse the repository at this point in the history
Fixes #3926
  • Loading branch information
Brian J. Cardiff committed Apr 20, 2017
1 parent 919bc4c commit 24c8321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/docs_main.cr
Expand Up @@ -29,6 +29,7 @@ require "./socket"
require "./spec"
require "./string/**"
require "./thread"
require "./weak_ref"
require "./xml"
require "./yaml"
require "./benchmark"
Expand Down
7 changes: 7 additions & 0 deletions src/weak_ref.cr
@@ -1,5 +1,11 @@
# Weak Reference class that allows a referenced object to be garbage-collected.
#
# ```
# ref = WeakRef.new("oof".reverse)
# p ref.value # => "foo"
# GC.collect
# p ref.value # => nil
# ```
class WeakRef(T)
@target : Void*

Expand All @@ -10,6 +16,7 @@ class WeakRef(T)
end
end

# :nodoc:
def self.allocate
ptr = GC.malloc_atomic(instance_sizeof(self)).as(self)
set_crystal_type_id(ptr)
Expand Down

0 comments on commit 24c8321

Please sign in to comment.