Eureka
Eureka copied to clipboard
Every BaseRow subclass leaks by default
Eureka version: 5.1.0
Tool used: Xcode memory graph
Steps to reproduce:
- Create a basic form with Eureka, with row models inheriting from BaseRow.
- Have this be pushed from a root view, so it is possible to destroy & recreate the form.
- Don't access leadingSwipe/trailingSwipe within the form.
- Access the form several times.
- Row instances are leaked.
Location of cause:
Line 104 of BaseRow.swift
public lazy var trailingSwipe = SwipeConfiguration(self)
Line 107 of BaseRow.swift
private lazy var _leadingSwipe = SwipeConfiguration(self)
Reason:
Lazy variables implicitly create a closure to produce the initial value. Because the initial value includes a reference to self
, the closure captures a strong reference to self
, producing a circular reference.
~Solution is unclear, generally f(self)
can be replaced by {[weak self] in guard let self = self else {return}; f(self)}
, but in this case there's a return value which cannot be Optional and SwipeConfiguration cannot be mocked, so some rearchitecting is required.~
You could in fact just remove the lazy keyword if that isn't required, or use {[unowned self] in SwipeConfiguration(self)}()
.
It seems like something in Eureka must access the values, because this isn't actually happening 100% of the time, just in a lot of cases.
Opened a PR: https://github.com/xmartlabs/Eureka/pull/1930