From b2e64e6265bc85303f48697a9d151cb07a0a16ad Mon Sep 17 00:00:00 2001
From: Maxime NATUREL <maxime.naturel@niji.fr>
Date: Thu, 28 Jul 2022 17:25:42 +0200
Subject: [PATCH 1/2] Fixing missing clear on TabLayoutMediator when view is
 destroyed

---
 .../ftueauth/FtueAuthSplashCarouselFragment.kt      | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt
index 0d86c4cd24..aaef1ddf01 100644
--- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt
@@ -51,6 +51,8 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
         private val carouselStateFactory: SplashCarouselStateFactory
 ) : AbstractFtueAuthFragment<FragmentFtueSplashCarouselBinding>() {
 
+    private var tabLayoutMediator: TabLayoutMediator? = null
+
     override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSplashCarouselBinding {
         return FragmentFtueSplashCarouselBinding.inflate(inflater, container, false)
     }
@@ -60,10 +62,19 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
         setupViews()
     }
 
+    override fun onDestroyView() {
+        tabLayoutMediator?.detach()
+        tabLayoutMediator = null
+        views.splashCarousel.adapter = null
+        super.onDestroyView()
+    }
+
     private fun setupViews() {
         val carouselAdapter = carouselController.adapter
         views.splashCarousel.adapter = carouselAdapter
-        TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }.attach()
+        tabLayoutMediator = TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }
+                .also { it.attach() }
+
         carouselController.setData(carouselStateFactory.create())
 
         val isAlreadyHaveAccountEnabled = vectorFeatures.isOnboardingAlreadyHaveAccountSplashEnabled()

From 2b58c42c8bdc3fffa3e3c0bf9bad07c901bbd16a Mon Sep 17 00:00:00 2001
From: Maxime NATUREL <maxime.naturel@niji.fr>
Date: Thu, 28 Jul 2022 17:30:05 +0200
Subject: [PATCH 2/2] Adding changelog entry

---
 changelog.d/6680.misc | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 changelog.d/6680.misc

diff --git a/changelog.d/6680.misc b/changelog.d/6680.misc
new file mode 100644
index 0000000000..f42160fbba
--- /dev/null
+++ b/changelog.d/6680.misc
@@ -0,0 +1 @@
+[FTUE] Memory leak on FtueAuthSplashCarouselFragment