'Memory Cycles in Flutter
Hello guys I am an iOS Developer building a Flutter app and I was wondering if the concept of memory cycle (retain cycle exists here). "Strong reference cycles negatively impact your application's performance. They lead to memory leaks and unexpected behaviour that is often hard to debug". By replacing a strong reference with a weak reference, the relationship between the objects remains intact and the strong reference cycle is broken. So in flutter there is no concept about weak reference. So how can you solve this problem, or there is no need to do that? Below I will leave an example.
abstract class MainScreenDelegate {
didTapButton();
}
class MainScreen implements MainScreenDelegate {
AnotherClass anotherClass;
@override
void initState() {
anotherClass = AnotherClass(this);
}
@override
void didTapButton() { }
}
class AnotherClass {
MainScreenDelegate delegate;
AnotherClass(this.delegate);
}
So the MainScreen has a strong reference to the AnotherClass and the AnotherClass has strong reference to the MainScreen. So are there any problems regarding the memory management in flutter or this is just an iOS related problem regarding their ARC (Automatic Reference Counting)? A fix in iOS would be to mark the delegate as weak.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
