1

I've tested mine project with Instruments (xCode Version 8.3.2) and encountered memory leaks in cases when I'm using [unowned self] in closures.

Changing to [weak self] and guard let strongSelf = self else { return } seems like solves the problem.

The questions is: why [unowned self] is leaking? Maybe it is just false alarm by Instruments?

enter image description here

landonandrey
  • 1,271
  • 1
  • 16
  • 26
  • The `[unowned self]` is not the root of the problem. It's just showing you that all of these properties are being leaked. The leaks tool doesn't show you the source of the leak, just were the leaked object was allocated. I'd suggest using "Debug memory graph" feature (https://stackoverflow.com/a/30993476/1271826) to identify what is keeping strong reference to self, because these particular closures are not the source of the problem. Right now you're looking at symptoms of the problem, not the source of the problem. – Rob Jul 11 '17 at 07:10
  • Thanks for reply. But why does it solves when I'm changing to weak self reference? – landonandrey Jul 11 '17 at 07:15
  • 1
    More likely, rather than solving any issue, it merely suppressed the warning. Your supposition is that you're seeing a "false positive" when using `[unowned self]`, but I'd suggest that it's equally likely that the "Leaks" tool simply isn't catching the leak (whose root cause rests elsewhere, not in the above code), when using `[weak self]`. You allocations graph is consistent with a true leak. I would not rely solely upon Leaks (it's notorious for not finding many types of memory issues), but rather use "Debug Memory Graph" feature or watch total memory usage in "Allocations" tool. – Rob Jul 11 '17 at 16:18

0 Answers0