View Single Post
Old 30th June 2014, 09:40   #17  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
That's very helpful, thanks guys.

More on topic, what about nested variables and arguments of functions pre-defined at the top-level script scope but called at runtime? According to the documentation
Quote:
The lifetime of variables defined at nested local scopes spans from the time of the definition in the nested local scope to the end of the nested local scope's lifetime.
It's well understood that such variables and arguments - not that there's much distinction in this regard - are not usable beyond the lifetime of the nested scope. But what about the memory occupied by them - when does that get released, specifically when called from runtime? If only when the script is closed, I would imagine the best way to limit per-frame memory growth from calling functions at runtime would be to use 'static' variables, i.e. globals and top-level script variables, wherever sensible? If so and assuming no calls to runtime functions from top-level code, are there any clear pros and cons to using globals vs. top-level script variables?

When is memory used by variables declared in "top-level" runtime code released? And, for the sake of completeness, that of variables and arguments of functions declared in runtime code (not that I can think of any good reason for that)?

EDIT: I suspect some or most of this is probably addressed by StainlessS' post above, in which case I humbly ask your indulgence for my limited understanding!

Last edited by fvisagie; 30th June 2014 at 09:48.
fvisagie is offline   Reply With Quote