Fix memory leak in .maintainLanguageMode

This commit is contained in:
Max Brunsfeld
2017-11-22 11:41:55 -08:00
parent cbdae916dd
commit 4810d13094
2 changed files with 64 additions and 19 deletions

View File

@@ -71,12 +71,22 @@ class GrammarRegistry extends FirstMate.GrammarRegistry {
}
})
this.subscriptions.add(pathChangeSubscription)
const destroySubscription = buffer.onDidDestroy(() => {
this.grammarScoresByBuffer.delete(buffer)
this.languageNameOverridesByBufferId.delete(buffer.id)
this.subscriptions.remove(destroySubscription)
this.subscriptions.remove(pathChangeSubscription)
})
this.subscriptions.add(pathChangeSubscription, destroySubscription)
return new Disposable(() => {
this.subscriptions.remove(pathChangeSubscription)
this.grammarScoresByBuffer.delete(buffer)
destroySubscription.dispose()
pathChangeSubscription.dispose()
this.subscriptions.remove(pathChangeSubscription)
this.subscriptions.remove(destroySubscription)
this.grammarScoresByBuffer.delete(buffer)
this.languageNameOverridesByBufferId.delete(buffer.id)
})
}