Memory leak when removing ChannelFragment

I’m using SendBird UIKit for Android. I only need the chat UI already created by you guys, so I created a ChannelFragment using its Builder pattern. When I remove it from view ( either by FragmentTransaction -> remove or by getSupportFragmentManager().popBackStackImmediate(); ) I get an instant memory leak by LeakCanary.

Apparently is because ChannelViewModel remains in memory when onDestroy gets called.

This is how I add the fragment:

ChannelFragment channelFragment = new ChannelFragment.Builder(mChannelUrl)

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(, channelFragment, "ChannelFragment").commit();

I have the databinding on my app build.gradle like:
dataBinding { enabled = true }

And is in my activity layout.

I’m using this library version:
implementation 'com.sendbird.sdk:uikit:2.0.2'

Here is the Heap Dump by LeakCanary:
│ GC Root: System class

├─ android.view.inputmethod.InputMethodManager class
│ Leaking: NO (InputMethodManager↓ is not leaking and a class is never
│ leaking)
│ ↓ static InputMethodManager.sInstance
├─ android.view.inputmethod.InputMethodManager instance
│ Leaking: NO (DecorView↓ is not leaking and InputMethodManager is a
│ singleton)
│ ↓ InputMethodManager.mCurRootView
├─ instance
│ Leaking: NO (PagerRecyclerView↓ is not leaking and View attached)
│ View is part of a window view hierarchy
│ View.mAttachInfo is not null (view attached)
│ View.mWindowAttachCount = 1
│ mContext instance of, wrapping
│ activity com.test.nm.view.StartupActivity with mDestroyed = false
│ ↓ View.mAttachInfo
├─ android.view.View$AttachInfo instance
│ Leaking: NO (PagerRecyclerView↓ is not leaking)
│ ↓ View$AttachInfo.mScrollContainers
├─ java.util.ArrayList instance
│ Leaking: NO (PagerRecyclerView↓ is not leaking)
│ ↓ ArrayList.elementData
├─ java.lang.Object array
│ Leaking: NO (PagerRecyclerView↓ is not leaking)
│ ↓ Object.[2]
├─ com.sendbird.uikit.widgets.PagerRecyclerView instance
│ Leaking: NO (View attached)
│ View is part of a window view hierarchy
│ View.mAttachInfo is not null (view attached)
│ View.mID =
│ View.mWindowAttachCount = 1
│ mContext instance of com.test.nm.view.StartupActivity with mDestroyed
│ = false
│ ↓ PagerRecyclerView.snappableScrollListener
│ ~~~~~~~~~~~~~~~~~~~~~~~
├─ com.sendbird.uikit.widgets.PagerRecyclerView$SnappableScrollListener instance
│ Leaking: UNKNOWN
│ Retaining 36 B in 2 objects
│ ↓ PagerRecyclerView$SnappableScrollListener.pager
│ ~~~~~
├─ com.sendbird.uikit.vm.ChannelViewModel instance
│ Leaking: UNKNOWN
│ Retaining 1.1 MB in 7140 objects
│ ↓ BaseViewModel.provider
│ ~~~~~~~~
╰→ com.sendbird.uikit.fragments.ChannelFragment instance
​ Leaking: YES (ObjectWatcher was watching this because com.sendbird.uikit.
​ fragments.ChannelFragment received Fragment#onDestroy() callback and
​ Fragment#mFragmentManager is null)
​ Retaining 1.1 MB in 7079 objects
​ key = 50884f5a-d36b-4943-9284-7c5d8385a275
​ watchDurationMillis = 12884
​ retainedDurationMillis = 7865


LeakCanary version: 2.6
Stats: LruCache[maxSize=3000,hits=6225,misses=80866,hitRate=7%]
Heap dump reason: user request
Analysis duration: 6158 ms

I appreciate in advance your help!


First off, welcome to the Sendbird Community. We’re happy you’re here. Let me take a look into this report and see what is going on.


1 Like


I noticed when I open one chat with the ChannelFragment, and then close it and open another, ChannelFragment displays the previous chat info and will display that info with any further chat.
I think this is because the ViewModel is retained for the first chat we opened.

I’m also seeing the same thing. I open a ChannelFragment with one channel url and if I build another channel fragment in the same activity even if I change the channel url it shows the previous channels chat messages. This is currently a show stopper for me in order to use Sendbird UIKit.

1 Like

Thank you for the report @Darin_Tanaka. We are currently awaiting further investigation from our Engineering team.



@RobertM @Darin_Tanaka
Thank you for your reporting!. We found the reason why the memory leak is caused and fixed the issue of using ChannelFragment on the same Activity.

We will release the new version after about 2 weeks. (This is our regular release)


Is there any beta release or any snapshot version so we can test as well?

Thanks for your work!

Sorry, there is no beta or snapshot version…! We test the new version internally and release it.

Hey! Any news on the release?


Hi, @tamasimecs new sdk which fixed this will be released within this week at the latest!

UIKit 2.1.0 has been released.!