From 7b6969a9308f31f4da882709d84eef70738ab9c5 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sun, 31 Mar 2013 18:55:01 +0000 Subject: [PATCH] Fix for ticket 215 - Memory leak? Invert design by replacing a stateful iterator with a callback. This avoids the (temporary) memory used by Lua to create and store closures. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@879 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleFuture.lua | 50 ++++++++++++++++++-------------------------------- OvaleState.lua | 11 ++++++++--- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/OvaleFuture.lua b/OvaleFuture.lua index 3082722..689bdb5 100644 --- a/OvaleFuture.lua +++ b/OvaleFuture.lua @@ -356,40 +356,26 @@ function OvaleFuture:COMBAT_LOG_EVENT_UNFILTERED(event, ...) end end ---[[----------------------------------------------------------------------- - Iterator for spells that are being cast or are in flight. - - The iterator returns: - spellId: ID of the spell - lineId: spell counter (see documentation for UNIT_SPELLCAST_START) - startCast: the time the spell started being cast - endCast: the time the spell cast will end - nextCast: the time the next spell can be cast - nocd: true if the spell has no cooldown - target: the target of the spell (can be nil) ---]]----------------------------------------------------------------------- -function OvaleFuture:InFlightSpells(now) +-- Apply spells that are being cast or are in flight. +function OvaleFuture:ApplyInFlightSpells(now, ApplySpell) local index = 0 local spellcast, si - return function() - while true do - index = index + 1 - if index > #self_activeSpellcast then return end - - spellcast = self_activeSpellcast[index] - si = OvaleData.spellInfo[spellcast.spellId] - -- skip over spells that are toggles for other spells - if not (si and si.toggle) then - Ovale:Logf("now = %f, spellId = %d, endCast = %f", now, spellcast.spellId, spellcast.stop) - if now - spellcast.stop < 5 then - return spellcast.spellId, spellcast.lineId, spellcast.start, spellcast.stop, spellcast.stop, spellcast.nocd, spellcast.target - else - tremove(self_activeSpellcast, index) - self_pool:Release(spellcast) - -- Decrement current index since item was removed and rest of items shifted up. - index = index - 1 - end - break + while true do + index = index + 1 + if index > #self_activeSpellcast then return end + + spellcast = self_activeSpellcast[index] + si = OvaleData.spellInfo[spellcast.spellId] + -- skip over spells that are toggles for other spells + if not (si and si.toggle) then + Ovale:Logf("now = %f, spellId = %d, endCast = %f", now, spellcast.spellId, spellcast.stop) + if now - spellcast.stop < 5 then + ApplySpell(spellcast.spellId, spellcast.lineId, spellcast.start, spellcast.stop, spellcast.stop, spellcast.nocd, spellcast.target) + else + tremove(self_activeSpellcast, index) + self_pool:Release(spellcast) + -- Decrement current index since item was removed and rest of items shifted up. + index = index - 1 end end end diff --git a/OvaleState.lua b/OvaleState.lua index e8ce254..3330f1e 100644 --- a/OvaleState.lua +++ b/OvaleState.lua @@ -61,6 +61,13 @@ OvaleState.powerRate = {} OvaleState.lastSpellId = nil -- +-- +local function ApplySpell(spellId, startCast, endCast, nextCast, nocd, targetGUID) + local self = OvaleState + self:ApplySpell(spellId, startCast, endCast, nextCast, nocd, targetGUID) +end +-- + -- function OvaleState:StartNewFrame() self.maintenant = Ovale.now @@ -186,9 +193,7 @@ end -- Apply the effects of spells that are being cast or are in flight, allowing us to -- ignore lag or missile travel time. function OvaleState:ApplyActiveSpells() - for spellId, _, startCast, endCast, nextCast, nocd, target in OvaleFuture:InFlightSpells(self.maintenant) do - OvaleState:ApplySpell(spellId, startCast, endCast, nextCast, nocd, target) - end + OvaleFuture:ApplyInFlightSpells(self.maintenant, ApplySpell) end -- Cast a spell in the simulator -- 1.7.9.5