Thread Tools Display Modes
04-01-10, 03:32 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
massive mem build up

So i noticed that my UI builds up mem usage every step you take and continues to do so till it hits some sort of garbage dump threshold and then starts over. Its primarily as you move. SO i think it has to do with my minimap and the coordinates. Can someone take a look at this and tell me maybe whats happening here and why its building so much mem up constantly? Is this normal? lol.

lua Code:
  1. local module = GrimUI:RegisterModule("MiniMap")
  2. -- Minimap
  3.  
  4. Minimap:ClearAllPoints()
  5. Minimap:Show()
  6. Minimap:SetPoint("BOTTOM", UIParent, 0, 11)
  7. Minimap:SetHeight(132)
  8. Minimap.SetHeight = GrimUI.Dummy
  9. Minimap:SetBackdropBorderColor(nil, nil, nil, nil)
  10. Minimap.SetBackdropBorderColor = GrimUI.Dummy
  11. Minimap:SetMaskTexture([[Interface\AddOns\!GrimUI\Art\Masks\Mask-SQUARE]])
  12. Minimap.ClearAllPoints = GrimUI.Dummy
  13. Minimap.SetPoint = GrimUI.Dummy
  14. Minimap.Hide = GrimUI.Dummy
  15. Minimap.SetWidth = GrimUI.Dummy
  16. Minimap.SetMaskTexture = GrimUI.Dummy
  17. Minimap:SetScale(0.95)
  18. Minimap:EnableMouseWheel(true)
  19. Minimap:SetScript("OnMouseWheel", function(self, arg1)
  20.     if(arg1 < 0) then
  21.         Minimap_ZoomIn()
  22.     else
  23.         Minimap_ZoomOut()
  24.     end
  25.     end)
  26. MinimapCluster:ClearAllPoints()
  27. MinimapCluster:SetPoint("BOTTOM", UIParent, 0, 11)
  28. MinimapCluster:SetHeight(2)
  29. MinimapCluster.SetPoint = GrimUI.Dummy
  30. MinimapCluster.SetHeight = GrimUI.Dummy
  31.  
  32. Minimap:SetScript("OnMouseUp", function(self, btn)
  33.         if btn == "RightButton" then
  34.             if ( WorldMapFrame:IsVisible() ) then
  35.                 HideUIPanel(WorldMapFrame);
  36.             else
  37.                 ShowUIPanel(WorldMapFrame);
  38.             end
  39.         elseif btn == "MiddleButton" then
  40.             _G.ToggleDropDownMenu(1, nil, _G.MiniMapTrackingDropDown, self)
  41.         else
  42.             _G.Minimap_OnClick(self)
  43.         end
  44.     end)
  45.  
  46. -- Start Cords Frame
  47.  
  48. local GUICordsFrame = CreateFrame('Button', "GUICordsFrame", UIParent)
  49. GUICordsFrame:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 0)
  50. GUICordsFrame:SetHeight(11)
  51. GUICordsFrame:SetWidth(80)
  52. GUICordsFrame:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
  53.  
  54. GUICordsFrame:RegisterEvent("MINIMAP_ZONE_CHANGED")
  55. GUICordsFrame:RegisterEvent("ZONE_CHANGED")
  56. GUICordsFrame:RegisterEvent("ZONE_CHANGED_INDOORS")
  57. GUICordsFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  58. GUICordsFrame.elapsed = 1
  59.  
  60. local GUICordsFrameBG = GUICordsFrame:CreateTexture(nil, "BACKGROUND")
  61. GUICordsFrameBG:SetTexture(0, 0, 0, .8)
  62. GUICordsFrameBG:SetAllPoints(GUICordsFrame)
  63.  
  64. local GUICordsFrameText = GUICordsFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  65. GUICordsFrameText:SetPoint("CENTER", GUICordsFrame, "CENTER", 0, 1)
  66. GUICordsFrameText:SetTextColor(1, 1, 1, 1)
  67. GUICordsFrameText:SetFont("Fonts\\FRIZQT__.TTF", 10, "NORMAL")
  68. GUICordsFrameText:SetJustifyH("CENTER")
  69.  
  70. GUICordsFrame:SetScript("OnUpdate", function(self)
  71.     local x,y = GetPlayerMapPosition("player")
  72.     if (x == 0) and (y == 0) and not IsInInstance() then
  73.         SetMapToCurrentZone()
  74.         local x,y = GetPlayerMapPosition("player")
  75.     end
  76.     GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
  77.     end)
  78.  
  79.  
  80. GUICordsFrame:SetScript("OnEvent", function(self)
  81.     if not WorldMapFrame:IsVisible() then
  82.         SetMapToCurrentZone()
  83.     end
  84. end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 03:44 PM   #2
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
It's due to all the junk strings you're creating, for one instead of:

Code:
GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
do

Code:
GUICordsFrameText:SetFormattedText("%.2f  %.2f", 100*x, 100*y)
And you should really throttle the updates to once every 0.20s-0.50s.
  Reply With Quote
04-01-10, 03:59 PM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Grimsin View Post
Code:
GUICordsFrame:SetScript("OnUpdate", function(self)
	local x,y = GetPlayerMapPosition("player")
	if (x == 0) and (y == 0) and not IsInInstance() then
		SetMapToCurrentZone()
		local x,y = GetPlayerMapPosition("player")
	end
	GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
	end)
You could move the vars. So they are reused.

Code:
local x,y
GUICordsFrame:SetScript("OnUpdate", function(self)
	x,y = GetPlayerMapPosition("player")
	if (x == 0) and (y == 0) and not IsInInstance() then
		SetMapToCurrentZone()
		x,y = GetPlayerMapPosition("player")
	end
	GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
	end)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
04-01-10, 04:06 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Shadowed View Post
It's due to all the junk strings you're creating, for one instead of:

Code:
GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
do

Code:
GUICordsFrameText:SetFormattedText("%.2f  %.2f", 100*x, 100*y)
And you should really throttle the updates to once every 0.20s-0.50s.
not exactly sure how to throtel it back and the explanation on wowwiki is in xml... or partly anyhow.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 04:20 PM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Grimsin View Post
not exactly sure how to throtel it back and the explanation on wowwiki is in xml... or partly anyhow.
OnUpdate is called with (self,elapsed). elapsed is the time since the last update.

Code:
local e = 0
local delay = .2
local function onupdate(self,elapsed)
  e = e + elapsed
  if e > delay then
    [... your stuff ...]
    e = 0
  end
end
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
04-01-10, 04:49 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
changed it to read
Code:
local UpdateInterval = 0.5
local TimeSinceLastUpdate = 0 
local x,y

GUICordsFrame:SetScript("OnUpdate", function(self, elapsed)
	
	TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed
	
	while (TimeSinceLastUpdate > UpdateInterval) do
	
	x,y = GetPlayerMapPosition("player")
	if (x == 0) and (y == 0) and not IsInInstance() then
		SetMapToCurrentZone()
	end
	
	GUICordsFrameText:SetText(format("%.2f  %.2f", 100*x, 100*y))
	
	TimeSinceLastUpdate = TimeSinceLastUpdate - UpdateInterval
	end
	end)


GUICordsFrame:SetScript("OnEvent", function(self)
	if not WorldMapFrame:IsVisible() then
		SetMapToCurrentZone()
	end
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 05:04 PM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Grimsin View Post
changed it to read
And ? Does it improve your memory usage ?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
04-01-10, 05:46 PM   #8
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Shadowed's solution is the only one that will work. Those two local variables won't affect memory usage at all the way you originally had it, since they get popped off the stack once the function returns.

Your memory usage keeps going up because like Shadowed said, every time you move to a new X,Y coordinate you generate a new string:
"80.20 20.53"
"80.21 20.52"
"80.21 20.51"
"80.22 20.50"

Lua only allocates memory for a string if it's unique though, so while you stand in place and your coordinates don't change, your memory usage quits going up.

WoW added the FontString:SetFormattedText method specifically to avoid this problem with garbage strings. When you use it, the text never gets allocated into Lua's string table.
  Reply With Quote
04-01-10, 06:14 PM   #9
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by Saiket View Post
WoW added the FontString:SetFormattedText method specifically to avoid this problem with garbage strings. When you use it, the text never gets allocated into Lua's string table.
Didn't know that, that's pretty nifty.
  Reply With Quote
04-01-10, 07:09 PM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
okay so i changed the formated text part, what your saying is it should not do the mem inc at all with that changed? i did the change to the update intervals and that reduced the speed of course at which it was increasing but...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 07:11 PM   #11
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
that sure appears to be the case after some testing. so i can bump the update speed back up to get a more accurate coord output then correct? and not see the mem inc?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 07:15 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
does appear to be the case? although i do have some sort of slow mem build up still somewhere and really should not be. it happens while standing still even lol didnt notice it before because the coords issue made it jump so much but yea standing still it incs slowly but surely.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
04-01-10, 11:01 PM   #13
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
Originally Posted by Grimsin View Post
does appear to be the case? although i do have some sort of slow mem build up still somewhere and really should not be. it happens while standing still even lol didnt notice it before because the coords issue made it jump so much but yea standing still it incs slowly but surely.
You're always going to have some increase in memory, you can't really avoid that unless your code does nothing. The reason you reduce the time between updates is to create the amount of strings you create, if you really wanted you could not update the string at all if player coords hasn't changed. What you're creating is called garbage memory and the garbage collect will gradually collect the memory you create. As long as you aren't creating a ton of it you don't have to worry.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » massive mem build up


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off