At it's simplest, you have a table of "active" frames. As they become no-longer "active" you move the frame to a "pool" table of inactive frames (delete the frame reference from the active table and add it to the inactive table).
If you need a new frame and the pool is empty, you create a new frame and add it to the active table otherwise take one from the pool table(delete the frame reference from the inactive table and add it to the active table).
This becomes more involved if you want to have frame types for different purposes and how far you want to abstract the pool concept but the general idea is the same.
To add a new active frame:
Lua Code:
local frame
if #MyInactiveFrameTable > 0 then -- 1 or more frames in the inactive table
frame = MyInactiveFrameTable[1] -- grab the 1st one
tremove(MyInactiveFrameTable, 1) -- and remove it from the table
else -- otherwise
-- create a new frame
frame = CreateFream(...)
-- add frame elements
end
tinsert(MyActiveFrameTable, frame) -- add the frame to the active table
-- update "frame" with new information to display
To "deactivate" active frame:
Lua Code:
tinsert(MyInactiveFrameTable, MyActiveFrameTable[1])
tremove(MyActiveFrameTable, 1)