From 719c4b402d263f01d3eb82b10f1a0a40671f0e02 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 10 May 2020 17:55:01 +0800 Subject: [PATCH] Clear group members after Bot completion --- .../src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt index 6747ea7b7..7151ff13d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt @@ -248,12 +248,17 @@ abstract class BotImpl constructor( init { coroutineContext[Job]!!.invokeOnCompletion { throwable -> + instances.removeIf { it.get()?.id == this.id } + network.close(throwable) offlineListener.cancel(CancellationException("Bot cancelled", throwable)) + // help GC release instances + groups.forEach { + it.members.delegate.clear() + } groups.delegate.clear() // job is cancelled, so child jobs are to be cancelled friends.delegate.clear() - instances.removeIf { it.get()?.id == this.id } } }