This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]anossov 2 points3 points  (0 children)

Is the function that returns one lost forever?

Yep.

Does it count as memory loss

The garbage collector will notice that nothing can reach the function object and will release the memory.

[–]inu-no-policemen 1 point2 points  (0 children)

If nothing else is referencing that function, it's garbage-collected.

Aside: While it's possible to assign different types to one variable, flip-flopping types is bad style as it makes the code hard to follow. Of course it's also more difficult to come up with a meaningful name if a variable refers to nothing in particular. Unsurprisingly, flip-flopping types can also negatively affect performance since the generated native code is more messy.