Didn't even think to do this instead.
Blizzard uses UnitCastingInfo() in their code with cast bars. Unless I'm missing something.
So just do SpellID = select(10, UnitCastingInfo(Unit)) or
_, _, _, _, _, _, _, _, _, SpellID = UnitCastingInfo(Unit)
This should produce zero garbage.
I tested it and gave back the spell id at the start and end of a cast.
This works on a UNIT_SPELLCAST_SUCCEEDED event. Not sure if lag would cause UnitCastingInfo() to return no info.
EDIT: Not reilable on a UNIT_SPELLCAST_SUCCEEDED sometimes UnitCastingInfo() for spellID returns nil.
Could do this not sure if it uses less memory or not
Code:
-- Set events for UNIT_SPELLCAST_START and SUCCEEDED here.
function SpellCasting(Event, Unit, Name, Rank, CastID)
if Event == 'UNIT_SPELLCAST_START' then
local _, _, _, _, _, _, _, _, _, SpellID = UnitCastingInfo(Unit)
LastSpell[CastID] = SpellID
else
SpellID = LastSpell[CastID]
LastSpell[CastID] = nil
end
print('>>', Event, SpellID)
end