Quantcast

Add :Clean() method to pool classes.

Johnny C. Lam [11-17-13 - 16:28]
Add :Clean() method to pool classes.

This method can be used to release resources held in tables allocated from
the pool object as part of releasing the item back to the pool via
pool:Release(item).  The pool:Clean(item) method is called shortly before
the table is wiped and returned to the table pool.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1184 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvalePool.lua
OvalePoolGC.lua
OvalePoolRefCount.lua
diff --git a/OvalePool.lua b/OvalePool.lua
index a93b63f..e77b265 100644
--- a/OvalePool.lua
+++ b/OvalePool.lua
@@ -56,11 +56,16 @@ end

 function OvalePool:Release(item)
 	assert(self.pool)
+	self:Clean(item)
 	wipe(item)
 	tinsert(self.pool, item)
 	self.unused = self.unused + 1
 end

+function OvalePool:Clean(item)
+	-- virtual function; override as needed.
+end
+
 function OvalePool:Drain()
 	self.pool = {}
 	self.size = self.size - self.unused
diff --git a/OvalePoolGC.lua b/OvalePoolGC.lua
index b2387c5..90b86a5 100644
--- a/OvalePoolGC.lua
+++ b/OvalePoolGC.lua
@@ -41,7 +41,11 @@ function OvalePoolGC:Get()
 end

 function OvalePoolGC:Release(item)
-	-- no-op
+	self:Clean(item)
+end
+
+function OvalePoolGC:Clean(item)
+	-- virtual function; override as needed.
 end

 function OvalePoolGC:Drain()
diff --git a/OvalePoolRefCount.lua b/OvalePoolRefCount.lua
index 7a1f9e2..a0f213c 100644
--- a/OvalePoolRefCount.lua
+++ b/OvalePoolRefCount.lua
@@ -59,6 +59,7 @@ local function ReleaseReference(item)
 		poolObject.refcount[item] = refcount - 1
 	else
 		poolObject.refcount[item] = nil
+		poolObject:Clean(item)
 		wipe(item)
 		tinsert(poolObject.pool, item)
 		poolObject.unused = poolObject.unused + 1
@@ -110,6 +111,10 @@ function OvalePoolRefCount:Release(item)
 	item:ReleaseReference()
 end

+function OvalePoolRefCount:Clean(item)
+	-- virtual function; override as needed.
+end
+
 function OvalePoolRefCount:Drain()
 	self.pool = {}
 	self.size = self.size - self.unused