Is there any sort of protocol or method for releasing objects from a class once they’re not needed?
I wrote a class and included a release() function which changes all of the self variables to nil:
function Prime:init(x)
-- you can accept and set parameters here
print( "Prime:init()", x )
self.x = x
self.didFindCoprimes = false
self.coprimes = {}
self.primitives = {}
end
function Prime:release()
self.x = nil
self.coprimes = nil
self.primitives = nil
end
I am using it in this context:
local i = 1
for i = 1, 20 do
local p = Prime( i )
if( p:findPrimitives() > 0 ) then
print( "primitives for ", p.x..":" )
tableIterator( p.primitives )
p:release()
end
end
I don’t know if it works tho, releasing the memory. Is there any way to interact with the garbage collector and know if memory a variable was pointing to was released?