The following code is used within my personal minimap addon. The code will cause a constant 3 kb/second gain of memory until garbage collection is run, and goes back down quite low. Is there a way to run this and not have constant garbage being built?
Lua Code:
local x, y, mapPosObject, mapID
tMinimapCoordsFrame:SetScript('OnUpdate', function(self, elapsed)
self.elapsed = self.elapsed + elapsed
while self.elapsed > 0.5 do --only update the coords 2/second
mapID = C_Map.GetBestMapForUnit('player')
if mapID then
mapPosObject = C_Map.GetPlayerMapPosition(mapID, 'player')
if mapPosObject then
x, y = mapPosObject:GetXY()
end
if (x and (x + y > 0)) then --hide if we don't have coords (instances)
tMinimapCoordsFrame.text:SetFormattedText('%.1f, %.1f', x*100, y*100)
else
tMinimapCoordsFrame:Hide()
end
end
self.elapsed = self.elapsed - 0.5
end
end)