Because the C_Map.GetPlayerMapPosition always create a new table as the result, so the memory usage will constantly increasing.
Here is a solution from other author:
Lua Code:
local MapRects = {}
function GetPlayerMapPos()
local mapid = C_Map.GetBestMapForUnit('player')
if not mapid then return end
local rects = MapRects[mapid]
if not rects then
rects = {}
local _, topleft = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(0,0))
local _, bottomright = C_Map.GetWorldPosFromMapPos(mapid, CreateVector2D(1,1))
bottomright:Subtract(topleft)
rects = { topleft.x, topleft.y, bottomright.x, bottomright.y }
MapRects[mapid] = rects
end
local x, y = UnitPosition("player")
if not x then return end
x, y = x - rects[1], y - rects[2]
return y / rects[4], x / rects[3]
end