class 'ReferenceCounter'

function ReferenceCounter:__init()
    self.nreferences = 0
end

function ReferenceCounter:__finalize()
end

function ReferenceCounter:__tostring()
    return tostring(self.nreferences)
end

function ReferenceCounter:AddRef()
    self.nreferences = self.nreferences + 1
end

function ReferenceCounter:Release()
    self.nreferences = self.nreferences - 1
    assert(self.nreferences >= 0)
end

function ReferenceCounter:GetNReferences()
    return self.nreferences
end