class Prism::ReferenceCounter(T)
- Prism::ReferenceCounter(T)
- Reference
- Object
Overview
A reference counter.
This counts the number of references to an object.
To properly use the reference you must initialize it with an object to be reference.
Then you must only retrives copies of the object with the #use
method.
Defined in:
prism/reference_pool/reference_counter.crConstructors
-
.new(resource : T)
Creates a new referenced resource.
Instance Method Summary
-
#is_orphaned? : Bool
Checks if this reference is orphaned (no references).
-
#trash_one : T
Trashes a single reference to the resource.
-
#use : T
Uses a new reference of this resource
Constructor Detail
Creates a new referenced resource.
The reference counter will remain at 0 until use call #use
Instance Method Detail
Checks if this reference is orphaned (no references). If this is true you should perform some clean up operations so that the resource can be garbage collected.
Trashes a single reference to the resource. This will return the resource value. This is just a convenience so we can clean up the value when the reference counter reaches 0. YOu should never use the returned value for anything other than cleanup.