Quantcast

Memory leaks

Scott Sibley [09-13-10 - 23:15]
Memory leaks
Filename
Modules/Bars.lua
Modules/Debug.lua
Modules/Histograms.lua
Modules/UnitTooltip.lua
diff --git a/Modules/Bars.lua b/Modules/Bars.lua
index c142ad4..3893153 100644
--- a/Modules/Bars.lua
+++ b/Modules/Bars.lua
@@ -192,23 +192,24 @@ local strataLocaleList = {"Background", "Low", "Medium", "High", "Dialog", "Full
 function clearBar(obj)
 	obj = mod.bars and mod.bars[obj]
 	if not obj then return end
-	for i, v in pairs(obj.bars) do
-		del(v)
-	end
+	del(obj.bar)
 	obj:Del()
+	if obj.secondBar then
+		del(obj.secondBar.bar)
+		obj.secondBar:Del()
+	end
 end

 function createBars()
 	if type(mod.bars) ~= "table" then mod.bars = {} end

-	for k, v in pairs(copy(self.db.profile.bars)) do
+	for k, v in pairs(self.db.profile.bars) do
 		if v.enabled then

 			local widget = mod.bars[v]
 			if not widget then
 				local bar = new()
-				local cfg = copy(v)
-				widget = mod.bars[v] or WidgetBar:New(mod.core, k, cfg, v.row or 0, v.col or 0, v.layer or 0, StarTip.db.profile.errorLevel, updateBar, bar)
+				widget = mod.bars[v] or WidgetBar:New(mod.core, k, v, v.row or 0, v.col or 0, v.layer or 0, StarTip.db.profile.errorLevel, updateBar, bar)
 				bar:SetStatusBarTexture(LSM:Fetch("statusbar", v.texture1))
 				bar:ClearAllPoints()
 				local arg1, arg2, arg3, arg4, arg5 = unpack(v.point)
@@ -252,7 +253,7 @@ function createBars()
 					bar:SetMinMaxValues(0, 100)
 					bar:Show()
 					bar:SetFrameStrata(strataNameList[widget.layer])
-					tinsert(mod.bars, {widget, bar})
+					mod.bars[v].secondBar = widget
 				end
 			end
 			widget.config.unit = StarTip.unit
@@ -350,6 +351,10 @@ function mod:SetUnit()
 	for i, bar in pairs(self.bars) do
 		bar:Start()
 		bar.bar:Show()
+		if bar.secondBar then
+			bar.secondBar:Start()
+			bar.secondBar.bar:Show()
+		end
 	end
 end

@@ -357,6 +362,10 @@ function mod:SetItem()
 	for i, bar in pairs(self.bars) do
 		bar:Stop()
 		bar.bar:Hide()
+		if bar.secondBar then
+			bar.secondBar:Stop()
+			bar.secondBar.bar:Hide()
+		end
 	end
 end

@@ -364,6 +373,10 @@ function mod:SetSpell()
 	for i, bar in pairs(self.bars) do
 		bar:Stop()
 		bar.bar:Hide()
+		if bar.secondBar then
+			bar.secondBar:Stop()
+			bar.secondBar.bar:Hide()
+		end
 	end
 end

@@ -375,6 +388,10 @@ function mod:OnHide()
 	for i, bar in pairs(self.bars) do
 		bar:Stop()
 		bar.bar:Hide()
+		if bar.secondBar then
+			bar.secondBar:Stop()
+			bar.secondBar.bar:Hide()
+		end
 	end
 end

diff --git a/Modules/Debug.lua b/Modules/Debug.lua
index 04b8b7f..6680802 100644
--- a/Modules/Debug.lua
+++ b/Modules/Debug.lua
@@ -2,6 +2,7 @@
 local mod = StarTip:NewModule("Debug", "AceEvent-3.0")
 mod.name = "Debug"
 mod.toggled = true
+mod.defaultOff = true
 local LibTimer = LibStub("StarLibTimer-1.0")
 local LibBuffer = LibStub("StarLibBuffer-1.0")
 local WidgetText = LibStub("StarLibWidgetText-1.0")
diff --git a/Modules/Histograms.lua b/Modules/Histograms.lua
index 797f258..d9aa040 100644
--- a/Modules/Histograms.lua
+++ b/Modules/Histograms.lua
@@ -275,7 +275,7 @@ local function createHistograms()
 			local newWidget
 			if not mod.histograms then mod.histograms = {} end
 			if not widget then
-				widget = WidgetHistogram:New(mod.core, k, copy(v), v.row or 0, v.col or 0, 0, StarTip.db.profile.errorLevel, updateHistogram)
+				widget = WidgetHistogram:New(mod.core, k, v, v.row or 0, v.col or 0, 0, StarTip.db.profile.errorLevel, updateHistogram)
 				newWidget = true
 				for i = 0, v.width - 1 do
 					local bar = new()
diff --git a/Modules/UnitTooltip.lua b/Modules/UnitTooltip.lua
index 35bfdb3..e607490 100644
--- a/Modules/UnitTooltip.lua
+++ b/Modules/UnitTooltip.lua
@@ -601,18 +601,6 @@ function mod:OnHide()
 	end
 end

-local function copy(t)
-	local new = {}
-	for k, v in pairs(t) do
-		if type(v) == "table" then
-			new[k] = copy(v)
-		else
-			new[k] = v
-		end
-	end
-	return new
-end
-
 local function escape(text)
 	return text:replace("|","||")
 end