GetRefCount
This function gets the current reference count for the object.
Syntax
Returns
The object reference count.
Example
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
directionallight = DirectionalLight:Create()
directionallight:SetRotation(35,45,0)
--Create a model
local model = Model:Load("Models/Characters/Barbarian/Barbarian.mdl")
--Get the first model surface
local surface = model:GetSurface(0)
--Get the surface material
local material = surface:GetMaterial()
--Get the material diffuse texture
texture = material:GetTexture(Texture.Diffuse)
System:Print(texture:GetRefCount()) --Prints "1" because this is the default reference count for all objects
--Increment the texture reference count
texture:AddRef()
System:Print(texture:GetRefCount()) --Prints "2" because we incremented the reference count
--Release the model. Because we allocated another copy of the texture,it will stay in memory and we can continue to use it.
model:Release()
System:Print(texture:GetRefCount()) --Prints "1" because the reference count was decremented when the model material was deleted
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()
--Draw the texture on screen
context:DrawImage(texture,0,0)
context:Sync()
end