I'm a little confused
>> It's important to be aware that free variables will be garbage collected if no strong references to them exist when execution reaches the end of the script.
In the light switch “worked example” there is a switch input state test on channelState which is local
if(state != channelState[ch])
Won’t this be garbage collected and test fail?
Shouldn't this be a global variable e.g. table-slot?
I’ve got 3 momentary switch inputs and want to maintain a toggle state for each.
Sorry can’t test this out, as like others, am awaiting the iPhone app.
We’re working out why this works (perhaps weak references are actually good enough to prevent garbage collection) and will get back to you.
Fen Consultants, UK
I’ve added more details to the wiki about the sort of problem that prompted that warning.
What’s going on in the lightswitch example, is that there’s (among others) a reference to channelState in the swEvent function, and there’s a reference to the swEvent function stored away by imp.configure. So every object has a “lifeline” and there’s nothing that the garbage collector can collect.