3 ms·
> How quickly can you tell whether or not this piece of code has a reference cycle? I'm curious. Does it? I would have guessed the "weak self" would have preve
by Matthias247 7y ago
> How quickly can you tell whether or not this piece of code has a reference cycle?
I'm curious. Does it? I would have guessed the "weak self" would have prevented it.
> In my view, reference counting does not combine very well with heavy use of closures.
It's one of the area where one has to be careful for sure! C++ with smart pointers and callbacks exhibits the same problem. And GC based languages make the pattern easier for sure. However I think this is not even the most critical error source in callback based designs. I think threading issues due to callbacks being executed on different threads cause the most trouble.
Therefore I think languages like Javascript and Dart - which only offer a single thread AND GC - are the the easiest to use for callback based designs.
- fauigerzigerk 7y agoYes, there's still a reference cycle because the outer closure implicitly captures self as well. The article explains it in greater detail. I agree that threading is another big gotcha, arguably a bigger one. Rust has some mitigations against that sort of thing.