Quantcast

More memory leaks. There has to be an end to this.

Scott Sibley [08-20-10 - 01:33]
More memory leaks. There has to be an end to this.
Filename
Modules/Text.lua
StarTip.lua
config.lua
diff --git a/Modules/Text.lua b/Modules/Text.lua
index caa9177..9400257 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -70,7 +70,7 @@ environment.unitHasAura = function(aura)
 end

 function copy(t)
-	local tmp = StarTip.new()
+	local tmp = {} --StarTip.new()
 	for k, v in pairs(t) do
 		if type(v) == "table" then
 			v = copy(v)
@@ -81,18 +81,6 @@ function copy(t)
 	return tmp
 end

---[[
-function del(t)
-	for k, v in pairs(t) do
-		if type(v) == "table" then
-			del(v)
-		end
-		t[k] = nil
-		StarTip.del(t)
-	end
-end
-]]
-
 local defaults = {profile={titles=true, empty = true, lines = {}, refreshRate = 100}}

 local defaultLines={
@@ -330,7 +318,7 @@ if type(self.memperc) == "number" then
     if not c then c = new() end
     if self.memperc > 50 then
         c.r, c.g, c.b = 1, 0, 0
-    elseif self.memperc < 0 then
+    elseif self.memperc <= 0 then
         c.r, c.g, c.b = 0, 0, 1
     else
         c.r, c.g, c.b = 0, 1, 0
@@ -358,6 +346,8 @@ if type(self.cpuperc) == "number" then
     if not c then c = new() end
     if self.cpuperc > 50 then
         c.r, c.g, c.b = 1, 0, 0
+    elseif self.cpuperc == 0 then
+	    c.r, c.g, c.b = 0, 0, 1
     else
         c.r, c.g, c.b = 0, 1, 0
     end
@@ -492,15 +482,18 @@ do
 				end
 			end
 		end
+		for i, v in ipairs(linesToDraw) do
+			StarTip.del(v)
+			tremove(linesToDraw, i)
+		end
 		if UnitExists("mouseover") then
 			GameTooltip:Hide()
 			GameTooltip:Show()
 		end
-		StarTip.del(linesToDraw)
-		linesToDraw = StarTip.new()
 	end
 end

+local tbl
 function mod:CreateLines()
     local llines = {}
     for i, v in ipairs(self.db.profile.lines) do
@@ -515,12 +508,12 @@ function mod:CreateLines()

                 local left, right, c, cc = '', ''
                 if v.right then
-                    right = mod.evaluator.ExecuteCode(environment, v.name, v.right)
-                    left = mod.evaluator.ExecuteCode(environment, v.name, v.left)
+                    right = mod.evaluator.ExecuteCode(environment, v.name .. " right", v.right)
+                    left = mod.evaluator.ExecuteCode(environment, v.name .. " left", v.left)
 					if right == "" then right = "nil" end
                 else
                     right = ''
-                    left = mod.evaluator.ExecuteCode(environment, v.name, v.left)
+                    left = mod.evaluator.ExecuteCode(environment, v.name .. " left", v.left)
                 end

                 if left and left ~= "" and right ~= "nil" and not v.deleted then
@@ -547,12 +540,14 @@ function mod:CreateLines()
 							v.rightObj = WidgetText:New(mod.core, v.name .. "right", v, 0, 0, v.layer or 0, StarTip.db.profile.errorLevel, updateFontString, mod.rightLines[lineNum])
 							v.update = tmp
 						end
-						tinsert(linesToDraw, {v.leftObj, mod.leftLines[lineNum]})
-						tinsert(linesToDraw, {v.rightObj, mod.rightLines[lineNum]})
+						tbl = StarTip.new(v.leftObj, mod.leftLines[lineNum])
+						tinsert(linesToDraw, tbl)
+						tbl = StarTip.new(v.rightObj, mod.rightLines[lineNum])
+						tinsert(linesToDraw, tbl)
                     else
 						GameTooltip:AddLine(' ')

-						if false and not v.leftObj or v.lineNum ~= lineNum then
+						if not v.leftObj or v.lineNum ~= lineNum then
 							if v.leftObj then v.leftObj:Del() end
 							v.value = v.left
 							local tmp = v.update
@@ -562,7 +557,8 @@ function mod:CreateLines()
 							v.lineNum = lineNum
 							v.update = tmp
 						end
-						tinsert(linesToDraw, {v.leftObj, mod.leftLines[lineNum]})
+						tbl = StarTip.new(v.leftObj, mod.leftLines[lineNum])
+						tinsert(linesToDraw, tbl)
                     end
 					if v.rightObj then
 						v.rightObj:Start()
@@ -571,7 +567,7 @@ function mod:CreateLines()
 						v.leftObj:Start()
 					end
 					v.lineNum = lineNum
-                end
+				end
 			end

         end
diff --git a/StarTip.lua b/StarTip.lua
index 93c7bd9..4a80e74 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -175,7 +175,6 @@ local options = {
 	}
 }

-local new, newDict, del
 do
 	local pool = setmetatable({},{__mode='k'})
 	function StarTip.new(...)
@@ -185,33 +184,34 @@ do
 			pool[t] = nil
 			for i=1, select("#", ...) do
 				t[i] = select(i, ...)
-			end
+			end
 		else
 			newtbl = true
 			t = {...}
 		end
+		local count = 0
+		for k, v in pairs(pool) do
+			count = count + 1
+		end
 		t.__starref__ = true
-
 		return t, newtbl
 	end
 	function StarTip.del(...)
 		local t = select(1, ...)
+
 		if type(t) ~= "table" or not t.__starref__ then return end
-		for i=1, select("#", ...) do
+
+		for i=2, select("#", ...) do
 			local t = select(i, ...)
-			if (t and type(t) ~= table) or t == nil then break end
-			for k, v in pairs(t) do
-				if type(k) == "table" then
-					StarTip.del(k)
-				end
-			end
+			if type(t) ~= table or t == nil then break end
+			StarTip.del(t)
 		end
-		local count = 0
 		for k, v in pairs(t) do
+			if type(v) == "table" then StarTip.del(v) end
 			t[k] = nil
 		end
 		t.__starref__ = nil
-		pool[t] = true
+		pool[t] = true
 	end
 end

diff --git a/config.lua b/config.lua
index dce9e15..f26450c 100644
--- a/config.lua
+++ b/config.lua
@@ -11,7 +11,7 @@ StarTip.config = {
 		["layers"] = 3,
 		["background"] = "d9ccf16f",
 		["rows"] = 6,
-		["cols"] = 40,
+		["cols"] = 30,
 		["layout-timeout"] = 0,
 		["update"] = 25,
 		["widget0"] = "widget_key_up",