# MessageCollection is not disposed

**URL:** <https://community.sendbird.com/t/messagecollection-is-not-disposed/4260>\
**Category:** Android\
**Created:** [March 25, 2022, 12:56am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260 "2022-03-25T00:56:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan\_Nguyen](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ethan_nguyen/32/2246_2.png) [@Ethan\_Nguyen](https://community.sendbird.com/u/Ethan_Nguyen)\
**Post date:** [March 25, 2022, 12:56am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/1 "2022-03-25T00:56:24Z")

</div>

Hi,  
When I logged in with a different account than the previous one, I receive these kinds of messages

 ![image](https://us1.discourse-cdn.com/flex020/uploads/sendbird/original/2X/e/e4fd08adf1950137c94d52287a0ced7246a0aaeb.png)

I tried to dispose MessageCollection, clear GroupChannel, disconnect Sendbird. But none of them works.  
Do I miss something or something working with Background Syncing

---

<div class="post-metadata">

**Author:** ![ScottKim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/scottkim/32/3330_2.png) [@ScottKim](https://community.sendbird.com/u/ScottKim)\
**Post date:** [March 25, 2022, 11:29am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/3 "2022-03-25T11:29:04Z")

</div>

Messages appear to be cached and data from the old account remains.  
Did you log out of your old account and log back in after init?

Clearing the cache only needs to be handled manually by the views in onCacheResult and onApiResult.

> <https://github.com/sendbird/sendbird-javascript-samples/blob/0ef7e5fa32bd2ca213708ebe566b67f775bf8596/javascript/javascript-basic-local-caching/src/js/components/ChatBody.js>

---

<div class="post-metadata">

**Author:** ![Ethan\_Nguyen](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ethan_nguyen/32/2246_2.png) [@Ethan\_Nguyen](https://community.sendbird.com/u/Ethan_Nguyen)\
**Post date:** [March 25, 2022, 11:37am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/4 "2022-03-25T11:37:30Z")

</div>

Yes, I call `sendBird.disconnect()` when logging out and `sendBird.connect` when logging in again with a different user

Besides, your example is for web not android

---

<div class="post-metadata">

**Author:** ![ScottKim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/scottkim/32/3330_2.png) [@ScottKim](https://community.sendbird.com/u/ScottKim)\
**Post date:** [March 29, 2022, 2:56am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/5 "2022-03-29T02:56:04Z")

</div>

Connecting and disconnecting is usually automatic.  
To log in as a new user, after sendBird.disconnect, you must log in as the new user, starting with an initialization rather than sendBird.connect.

SendBird.init(APP\_ID, getApplicationContext());

If that doesn’t work, here’s a method to clear the caching:

> **[Local caching | Chat Android SDK | Sendbird Docs](https://sendbird.com/docs/chat/v3/android/guides/local-caching#2-other-methods)**
>
> Learn how local caching works in Chat SDK for Android.

---

<div class="post-metadata">

**Author:** ![Ethan\_Nguyen](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ethan_nguyen/32/2246_2.png) [@Ethan\_Nguyen](https://community.sendbird.com/u/Ethan_Nguyen)\
**Post date:** [March 29, 2022, 9:27am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/6 "2022-03-29T09:27:42Z")

</div>

Try that but still does not work

```auto
public async clearCurrentCache(): Promise<void> {
    this.sendBird.clearCachedMessages(Array.from(this.groupChannels.keys()));
    this.clearGroupChannels();
    this.sendBird.removeAllChannelHandlers();
    this.sendBird.removeAllConnectionHandlers();
    this.sendBird.removeAllUserEventHandler();
    await this.sendBird.clearCachedData();
    await this.sendBird.disconnect();
    this._sendBird = undefined;
  }

  private clearGroupChannels() {
    this.groupChannels.forEach(groupChannel => groupChannel.dispose());
    this.groupChannels = new Map();
  }

```

Group Channel:

```auto
public dispose(): void {
    this.messageCollection.dispose();
    this.eventHandlers = [];
  }

```

---

<div class="post-metadata">

**Author:** ![ScottKim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/scottkim/32/3330_2.png) [@ScottKim](https://community.sendbird.com/u/ScottKim)\
**Post date:** [April 1, 2022, 1:44am UTC](https://community.sendbird.com/t/messagecollection-is-not-disposed/4260/7 "2022-04-01T01:44:44Z")

</div>

Regardless of MessageCollection, existing channel information does not exist when you log in as a new user.  
For example, when I log in as user1 and when I log in as user2, do I get a different list of channels?  
(user1 and user2 are subscribed to different channels)

If possible, could you please video record the process and show it to me?

The crux of the problem may be wrong.  
You said that the MessageCollection is not disposed, but the image is “User must be a member” . Image error messages can have many causes.

No errors when logging back into your old account?
