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 ) 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.