Quantcast WoWInterface - View Single Post - Memory Leak ?
Thread: Memory Leak ?
View Single Post
05-05-17, 12:41 AM   #10
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
Thanks to all for the kind replies.

Now I have collected all your inputs and this is the final (actual ? ) code:

Lua Code:
  1. local ADDON = ...
  2. local playerName = UnitName("player")
  3. local string_format = string.format
  4. local tooltip
  5.  
  6. local TYPE70 = LE_GARRISON_TYPE_7_0
  7. local TYPE60 = LE_GARRISON_TYPE_6_0
  8.  
  9. local FOLTYPE70 = LE_FOLLOWER_TYPE_GARRISON_7_0
  10. local FOLTYPE60 = LE_FOLLOWER_TYPE_GARRISON_6_0
  11. local FOLTYPE62 = LE_FOLLOWER_TYPE_SHIPYARD_6_2
  12.  
  13. local GetAvailableMissions = C_Garrison.GetAvailableMissions
  14. local GetInProgressMissions = C_Garrison.GetInProgressMissions
  15. local GetCompleteMissions = C_Garrison.GetCompleteMissions
  16.  
  17. local LEGION = {
  18.     avl = 0,
  19.     pro = 0,
  20.     fin = 0,
  21. }
  22.  
  23. local DRAENOR = {
  24.     avl = 0,
  25.     pro = 0,
  26.     fin = 0,
  27. }
  28.  
  29. local SHIP = {
  30.     avl = 0,
  31.     pro = 0,
  32.     fin = 0,
  33. }
  34.  
  35. local frame = CreateFrame("Frame")
  36. frame:SetScript("OnEvent", function(self, event, arg1)
  37.  
  38.     if event == "ADDON_LOADED" and arg1 == "Blizzard_OrderHallUI" then
  39.         OrderHallCommandBar:Hide()
  40.         OrderHallCommandBar.Show = function() return end
  41.         GarrisonLandingPageTutorialBox:SetClampedToScreen(true)
  42.         self:UnregisterEvent("ADDON_LOADED")
  43.     end
  44.  
  45.     if C_Garrison.GetGarrisonInfo(TYPE70) then
  46.         LEGION["avl"] = #GetAvailableMissions(FOLTYPE70)
  47.         LEGION["pro"] = #GetInProgressMissions(FOLTYPE70)
  48.         LEGION["fin"] = #GetCompleteMissions(FOLTYPE70)
  49.     end
  50.    
  51.     if C_Garrison.GetGarrisonInfo(TYPE60) then
  52.         DRAENOR["avl"] = #GetAvailableMissions(FOLTYPE60)
  53.         DRAENOR["pro"] = #GetInProgressMissions(FOLTYPE60)
  54.         DRAENOR["fin"] = #GetCompleteMissions(FOLTYPE60)           
  55.  
  56.         if C_Garrison.HasShipyard() then
  57.             SHIP["avl"] = #GetAvailableMissions(FOLTYPE62)
  58.             SHIP["pro"] = #GetInProgressMissions(FOLTYPE62)
  59.             SHIP["fin"] = #GetCompleteMissions(FOLTYPE62)                          
  60.         end    
  61.     end
  62.  
  63. end)
  64. frame:RegisterEvent("ADDON_LOADED")
  65. frame:RegisterEvent("GARRISON_UPDATE")
  66. frame:RegisterEvent("GARRISON_MISSION_LIST_UPDATE")
  67. frame:RegisterEvent("GARRISON_MISSION_FINISHED")
  68.  
  69.  
  70. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  71. local dataobj = ldb:NewDataObject(ADDON, {
  72.     type = "data source",
  73.     icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  74.     text = "Hall"
  75. })
  76.  
  77. dataobj.OnClick = function(self, button)  
  78.  
  79.     if InCombatLockdown() then
  80.         return
  81.     end
  82.    
  83.     if      button == "LeftButton" then
  84.         if C_Garrison.GetGarrisonInfo(TYPE70) then
  85.             if (GarrisonLandingPage and GarrisonLandingPage:IsShown()) then
  86.                 HideUIPanel(GarrisonLandingPage);
  87.             else
  88.                 ShowGarrisonLandingPage(TYPE70);
  89.             end
  90.         end
  91.     elseif  button == "RightButton" then   
  92.         if C_Garrison.GetGarrisonInfo(TYPE60) then
  93.             if (GarrisonLandingPage and GarrisonLandingPage:IsShown()) then
  94.                 HideUIPanel(GarrisonLandingPage);
  95.             else
  96.                 ShowGarrisonLandingPage(TYPE60);
  97.             end
  98.         end
  99.     elseif  button == "MiddleButton" then
  100.     end
  101.    
  102. end
  103.  
  104. function dataobj.OnTooltipShow(tooltip)
  105.     tooltip:AddLine(ADDON)
  106.     tooltip:AddLine(" ")
  107.     tooltip:AddLine("Missions",1,1,1,1)
  108.  
  109.     if C_Garrison.GetGarrisonInfo(TYPE70) then
  110.        
  111.         tooltip:AddDoubleLine("Legion Order Hall",
  112.                 string_format("|cFFFFFFFF%d|r", LEGION["avl"]) .. " "  ..
  113.                 string_format("|cFFFFFF00%d|r", LEGION["pro"] - LEGION["fin"]) .. " " ..
  114.                 string_format("|cFF00803F%d|r", LEGION["fin"])
  115.         )
  116.  
  117.     end
  118.    
  119.     if C_Garrison.GetGarrisonInfo(TYPE60) then
  120.  
  121.         tooltip:AddDoubleLine("Draenor Garrison",
  122.                 string_format("|cFFFFFFFF%d|r", DRAENOR["avl"]) .. " "  ..
  123.                 string_format("|cFFFFFF00%d|r", DRAENOR["pro"] - DRAENOR["fin"]) .. " " ..
  124.                 string_format("|cFF00803F%d|r", DRAENOR["fin"])
  125.         )
  126.  
  127.         if C_Garrison.HasShipyard() then
  128.             tooltip:AddDoubleLine("Draenor Shipyard",
  129.                     string_format("|cFFFFFFFF%d|r", SHIP["avl"]) .. " "  ..
  130.                     string_format("|cFFFFFF00%d|r", SHIP["pro"] - SHIP["fin"]) .. " " ..
  131.                     string_format("|cFF00803F%d|r", SHIP["fin"])
  132.             )
  133.         end
  134.        
  135.     else
  136.    
  137.         tooltip:AddLine("No Hall or Garrison yet",1,1,0,0)
  138.    
  139.     end
  140.    
  141.     tooltip:AddLine(" ")
  142.     tooltip:AddDoubleLine("Left Click",     "Class Hall")
  143.     tooltip:AddDoubleLine("Right Click",    "Garrison")
  144. end

Using a frame to collect data basing on events surely helped in decreasing the memory allocated ... even if it grows a lot the same when you click to get the panels but I think it can't be avoided

Thanks again.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote