I'm using it in a buff addon I'm currently working on. Here's a (very) trimmed down version.
Lua Code:
local pool
local function CreateBuff(pool)
--create a new control frame
local buff = ZO_ObjectPool_CreateControl("MyBuffTemplate", pool, parentFrame)
--do other stuff with buff object
--return it for use
return buff
end
local function RemoveBuff(control)
--do stuff when you don't need a frame anymore
control:SetHidden(true)
end
local function UpdateBuffs()
local myBuff
for i = 1, GetNumBuffs("player") do
--if a control with this id # doesn't exist yet, create it, otherwise just return the one we have
myBuff = pool:AcquireObject(i)
--do more stuff with myBuff
end
end
local function Initialize()
--create a new pool to get my controls from
pool = ZO_ObjectPool:New(CreateBuff, RemoveBuff)
EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_EFFECT_CHANGED, UpdateBuffs)
end
EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, function(event, addon)
if addon == "MyAddon" then
Initialize()
end
end)