From 531cee739449a7d83856b2c0f314aebb95f102d0 Mon Sep 17 00:00:00 2001 From: DatDang Date: Fri, 5 Apr 2024 10:22:32 +0700 Subject: [PATCH] TF-2533 Create ADR for controller memory leak --- ...fix-memory-leak-with-controller-dispose.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/adr/0043-fix-memory-leak-with-controller-dispose.md diff --git a/docs/adr/0043-fix-memory-leak-with-controller-dispose.md b/docs/adr/0043-fix-memory-leak-with-controller-dispose.md new file mode 100644 index 000000000..8493ac38c --- /dev/null +++ b/docs/adr/0043-fix-memory-leak-with-controller-dispose.md @@ -0,0 +1,22 @@ +# 43. Fix memory leak with Controller's `dispose()` + +Date: 2024-04-05 + +## Status + +- Issues: + - [Memory footprint #2533](https://github.com/linagora/tmail-flutter/issues/2533) + +## Context + +- Majority, if not all, of TMail's `Controller` are created by extending `BaseController`. Everytime a new state arrives, `viewState`, of `BaseController` is assigned with new value. This value is never disposed so its reference lives on even if the `Controller` itself dies that causes memory leak. + +## Decision + +- A new state with name `UIClosedState` was created for clarification. It extends `BaseUIState` which extends `UIState`. +- `viewState` will be assigned to `UIClosedState()` inside the `dispose()` method of the memory-leaking controller, so the reference to its previous value is destroyed. +- Ideally, this value reasignment of `viewState` should happen inside `BaseController`'s `dispose()`. However, current state of project is not allowed for side effect that can be caused by app wide changes. This can change in the future. + +## Consequences + +- `SingleEmailController` & `ComposerController`'s memory leak problem are resolved.