"EnTerr" wrote:
Probably. But don't obsess about reference counts, just have faith that it works "like magic" and in most cases you have nothing to worry about, the system takes care of objects lifetime and disposal.
In my defense, the "errors" / "misdiagnosed error/bug (proper exiting of my app)" / "redesign" of the Roku main menu / etc have lead me to be ... a tad bit "concerned"
😉 "EnTerr" wrote:
Avoid using globals (GetGlobalAA()) when you can pass something as argument and you should be fine, since leaving out of nested functions will be cleaning behind.
I don't understand what "since leaving out of nested functions will be cleaning behind" means exactly. Can you expound on it a bit?
My logic/assumption ( flawed though it might be ) was:
that I was using up too much memory and/or confusing the Roku so much that it wasn't freeing memory on exit of my app. Repeated running of this caused greater and greater memory issues. As has been pointed out to me this
should not have been possible, so my perception of the issues I've been having ( see response above ) are probably incorrect.
My other desire was to limit the passing of parameters unnecessarily *AND* to make the code easier to edit as a shorter parameter list seems more helpful to me.... but now that I've taken this to an extreme, passing "m" doesn't tell me much about what the function needs or will do.
AS per freeing memory: do methods, functions attached to objects, free their local variables differently than global functions?
"EnTerr" wrote:
For edu-tainment's sake, i made here an artificial example to demonstrate how one "memory leak" happens:
<see above>
So i got a factory function Stack(n) that constructs a stack with N elements and 2 methods, `push` and `pull` that respectively add and remove elements. Then i shove 10 roScreens on that stack, then i take them back and even invalidate the last one. And yet, they are not all gone. How come? - figuring that out will be a good exercise.
- Is there something going on with the stack being initialized to 100 instead of 10?
and/or the pull() function only changing the ptr variable and not doing anything with the actual memory reserved in the array?
Arrays use contiguous memory, yet I thought I read that BrightScript does allow individual elements to be "released", am I getting warmer?
... or completely cold?
If we were to debug such a code fragment, what tools do we have to check the memory use?