Hi! That sounds spot on.
The reasoning behind the lock counter is that sometimes (GC, as you mentioned, or when compacting variables) the interpreter needs to know when a variable is 'in use' and so cannot be moved around or freed.
The vars have a 'lock counter' which you can read either using the trace() JS command or with jsvGetLocks() from C. Basically if the variable is just sitting there not being used by any C code, it should have no locks at all.
If you have a pointer to the variable in your C code, the variable should be locked.
If you compile without RELEASE=1 some assertions get built in, and those check for the lock count getting too high or decremented too much - so it's a good way to sanity check what you're doing (even if you have to temporarily pull out some features in order to get the build to fit in flash)
Hope that helps!
© Espruino, powered by microcosm.
Report a problem