Code: Select all
function Window:Remove()
-- removing stuffs here
end

Code: Select all
function Window:Remove()
-- removing stuffs here
end
and removing all references to it would be done how? just setting it to self = nil?raidho36 wrote:Unless they have specific function to destroy the window, you should hide it and remove all references to it, thereby making it garbage-collectible. The garbage collector, seeing as the table is no longer used, will collect it and remove from memory. Note that while technically still around, the moment you remove last reference it for all intents and purposes ceases to exist. And since rendering requires that you'd access it, implying that there's a reference to it, if you remove that reference it will not be rendered, too.
No, you must have the window(s) stored somewhere else. For example you might have a list of Windows called 'windows', each of which you callCosmicFloppyDisk wrote:and removing all references to it would be done how? just setting it to self = nil?raidho36 wrote:Unless they have specific function to destroy the window, you should hide it and remove all references to it, thereby making it garbage-collectible. The garbage collector, seeing as the table is no longer used, will collect it and remove from memory. Note that while technically still around, the moment you remove last reference it for all intents and purposes ceases to exist. And since rendering requires that you'd access it, implying that there's a reference to it, if you remove that reference it will not be rendered, too.
Code: Select all
print( type(love) )
if false then
baby:hurt(me)
end
Code: Select all
-- create table
mytable = {}
-- remove reference
mytable = nil
-- collect
collectgarbage("collect")
No, you have to remove every single reference to the "object" so that there is no way to access it from Lua.just setting it to self = nil?
Code: Select all
function myfunc(...)
local arg = {...}
for i = 1, #arg do
local a = arg[i]
-- do stuff
end
end
Code: Select all
function myfunc2(...)
for i = 1, select('#', ...) do
local a = select(i, ...)
-- do stuff
end
end
Specifically, the second one is probably slower because of calling select with a dynamic index value. LuaJIT can't compile that, but it can compile literal index values like '#' or 2 (as of last time I checked anyway).ivan wrote: The second function is slower during execution because it calls "select" for each item, but the first creates more garbage.
It's a trade-off, so to "really" compare the performance of both functions you have to use "collectgarbage".
Code: Select all
function doStuffA (...)
for i = 1, select('#', ...) do
local a = select(i, ...)
print(a)
end
end
function doStuffB (a, ...)
if a ~= nil then
print(a)
return doStuffB(...)
end
end
Users browsing this forum: Amazon [Bot] and 11 guests