To answer a question that shows up a lot here, frames cannot be "removed" from memory. They stay persistent throughout an entire session. The best you can do is recycle frames by use of "Frame Pools".
Here's a simpler way and keeping a separate table just for active frames in a frame pool is unnecessary if you're already keeping track of them in other parts of your code.
Lua Code:
local FramePool={};
local function FramePool_Acquire()
return table.remove(FramePool) or CreateFrame("Frame");-- Returns a frame if there is one in the pool or creates one if empty
end
local function FramePool_Release(frame)
table.insert(frame);-- Stores frame in pool
end
Note: You should create a different pool for each frame template you wish to use in order to keep them from getting mixed up.
If you're feeling adventurous, you might want to take a look at Blizzard's implementation of frame and object pools in
SharedXML\Pools.lua.
You'll want to pay attention to
CreateFramePool() for a singilar frame pool and
CreatePoolCollection() to manage different templates.