Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-22-15, 01:00 PM   #1
Spyro
A Fallenroot Satyr
 
Spyro's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2011
Posts: 23
Will this be Garbage Collected?

Hi guyz.

I have made a function to execute code in the next frame, mainly for getting correct GetLeft(), GetRight(), GetPoint() values after changing the anchor point of a Frame (because the data that those functions return is not updated until the next frame):
Lua Code:
  1. -- Frame to execute code in the next frame
  2. local _RunNextFrame = CreateFrame("Frame") -- Frame whose OnUpdate will execute the functions in the next frame
  3. _RunNextFrame:Hide() -- OnUpdate disabled by default
  4.  
  5. -- OnUpdate script which iterates thru all the functions stored in the frame to execute them
  6. _RunNextFrame:SetScript("OnUpdate", function(self)
  7.   for i = 1, #self do
  8.     self[i]() -- Executing function
  9.     self[i] = nil -- Removing the reference to the function (to be garbage collected)
  10.   end
  11.   self:Hide() -- Disabling OnUpdate
  12. end)
  13.  
  14. -- RunNextFrame()
  15. -- Executes a function in the next frame.
  16. local function RunNextFrame(Function)
  17.   _RunNextFrame[#_RunNextFrame + 1] = Function -- Storing a reference to the function in the frame
  18.   _RunNextFrame:Show() -- Enabling the OnUpdate of the frame
  19. end
  20.  
  21. -- Example application
  22. -- Getting the distance from the left edge of the screen to the right edge of the PlayerFrame after changing its anchor point
  23. local PlayerFrameRight
  24.  
  25. PlayerFrame:ClearAllPoints()
  26. PlayerFrame:SetPoint("CENTER", UIParent, "CENTER", -255, 20)
  27.  
  28. RunNextFrame(function()
  29.   PlayerFrameRight = PlayerFrame:GetRight()
  30. end)
The question is: Will the anonymous function that I pass as argument to RunNextFrame() be garbage collected?
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Will this be Garbage Collected?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off