Will this be Garbage Collected?
Hi guyz. :cool:
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:
|
Yes, functions are garbage-collected. The only things that aren't are frames.
However, if your actual code is anything like your fake example code (seriously, why do you people post this crap? just post your real code :mad:) then you should just assign your "anonymous" function to a variable so you can reuse it instead of creating endless duplicates of it, or better yet, don't bother caching the right position at all; if you actually need to determine the right position of a frame so often that just calling frame:GetRight() is slowing things down and caching offers a meaningful benefit, there's probably a more fundamental flaw with your program design. |
Relying on garbage collection is the last thing you should do in any circumstance. Memory expensive objects such as functions and tables can eat up a lot of memory if repeatedly created and left for garbage collection in a short amount of time. When garbage collection eventually does happen, it puts a heavy load on the CPU trying to free the associated memory of each object. Lua does do this in steps to try to keep the host program running stable, but it's still a CPU-intensive task nonetheless.
|
All times are GMT -6. The time now is 06:26 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI