Quantcast WoWInterface - View Single Post - Minimap Coordinates Memory Usage Optimization
View Single Post
07-10-19, 08:03 AM   #1
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Minimap Coordinates Memory Usage Optimization

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:
  1. local x, y, mapPosObject, mapID
  2. tMinimapCoordsFrame:SetScript('OnUpdate', function(self, elapsed)
  3.     self.elapsed = self.elapsed + elapsed
  4.     while self.elapsed > 0.5 do --only update the coords 2/second
  5.         mapID = C_Map.GetBestMapForUnit('player')
  6.         if mapID then
  7.             mapPosObject = C_Map.GetPlayerMapPosition(mapID, 'player')
  8.             if mapPosObject then
  9.                 x, y = mapPosObject:GetXY()
  10.             end
  11.             if (x and (x + y > 0)) then --hide if we don't have coords (instances)
  12.                 tMinimapCoordsFrame.text:SetFormattedText('%.1f, %.1f', x*100, y*100)
  13.             else
  14.                 tMinimapCoordsFrame:Hide()
  15.             end
  16.         end
  17.  
  18.         self.elapsed = self.elapsed - 0.5
  19.     end
  20. end)
  Reply With Quote