Added Object:release. Calling it is the equivalent of removing all Lua-side references to an object and doing a full garbage collection cycle (thus deleting the object from memory if nothing else in LÖVE's code is referencing it).

Any attempt to call a method on the object after it has been released will result in an error. Object:release() returns true if it was successful, or false if not (if it has already been released previously).

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-10-06 21:59:01 -03:00
parent bfb00239fd
commit 37520bd18b
7 changed files with 69 additions and 9 deletions
+6
View File
@@ -161,6 +161,7 @@ local _getWidth = ImageData.getWidth
local _getHeight = ImageData.getHeight
local _getDimensions = ImageData.getDimensions
local _getFormat = ImageData.getFormat
local _release = ImageData.release
-- Table which holds ImageData objects as keys, and information about the objects
-- as values. Uses weak keys so the ImageData objects can still be GC'd properly.
@@ -270,5 +271,10 @@ function ImageData:getFormat()
return objectcache[self].format
end
function ImageData:release()
objectcache[self] = nil
return _release(self)
end
-- DO NOT REMOVE THE NEXT LINE. It is used to load this file as a C++ string.
--)luastring"--"
+1 -1
View File
@@ -126,7 +126,7 @@ static FFI_RandomGenerator ffifuncs =
[](Proxy *p) -> double // random()
{
// FIXME: We need better type-checking...
if (p == nullptr || !typeFlags[p->type][MATH_RANDOM_GENERATOR_ID])
if (p == nullptr || p->object == nullptr || !typeFlags[p->type][MATH_RANDOM_GENERATOR_ID])
return 0.0;
RandomGenerator *rng = (RandomGenerator *) p->object;
@@ -72,6 +72,8 @@ local ffifuncs = ffi.cast("FFI_RandomGenerator *", ffifuncspointer)
-- Overwrite some regular love.math functions with FFI implementations.
function RandomGenerator:random(l, u)
-- TODO: This should ideally be handled inside ffifuncs.random
if self == nil then error("bad argument #1 to 'random' (RandomGenerator expected, got no value)", 2) end
local r = tonumber(ffifuncs.random(self))
return getrandom(r, l, u)
end
+6
View File
@@ -46,6 +46,7 @@ local _getSampleCount = SoundData.getSampleCount
local _getSampleRate = SoundData.getSampleRate
local _getChannels = SoundData.getChannels
local _getDuration = SoundData.getDuration
local _release = SoundData.release
-- Table which holds SoundData objects as keys, and information about the objects
-- as values. Uses weak keys so the SoundData objects can still be GC'd properly.
@@ -133,5 +134,10 @@ function SoundData:getDuration()
return objectcache[self].duration
end
function SoundData:release()
objectcache[self] = nil
return _release(self)
end
-- DO NOT REMOVE THE NEXT LINE. It is used to load this file as a C++ string.
--)luastring"--"