class Prism::ReferenceCounter(T)

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(resource : T) #

Creates a new referenced resource. The reference counter will remain at 0 until use call #use


[View source]

Instance Method Detail

def is_orphaned? : Bool #

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.


[View source]
def trash_one : T #

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.


[View source]
def use : T #

Uses a new reference of this resource


[View source]