Fix memory leaks
This commit is contained in:
@@ -7,7 +7,7 @@ export interface DataSourceState {
|
||||
}
|
||||
|
||||
export class DataSourceStateMachine {
|
||||
public onUpdate = new EventDispatcher<DataSourceState, DataSourceStateMachine>(this)
|
||||
public onUpdate = new EventDispatcher<DataSourceState, DataSourceStateMachine>()
|
||||
private state: DataSourceState = {
|
||||
error: undefined,
|
||||
connected: false,
|
||||
|
||||
@@ -16,7 +16,7 @@ export class Tree<ViewModel> extends TreeNode<ViewModel> {
|
||||
public isTree = true
|
||||
private cachedHash = `${Math.random()}`
|
||||
private unmergedMessages: ChangeBuffer = new ChangeBuffer()
|
||||
public didReceive = new EventDispatcher<void, Tree<ViewModel>>(this)
|
||||
public didReceive = new EventDispatcher<void, Tree<ViewModel>>()
|
||||
|
||||
constructor() {
|
||||
super(undefined, undefined)
|
||||
@@ -27,6 +27,13 @@ export class Tree<ViewModel> extends TreeNode<ViewModel> {
|
||||
this.didReceive.dispatch()
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
super.destroy()
|
||||
this.updateSource && this.updateSource.unsubscribe(this.subscriptionEvent, this.handleNewData)
|
||||
this.updateSource = undefined
|
||||
this.didReceive.removeAllListeners()
|
||||
}
|
||||
|
||||
public updateWithConnection(emitter: EventBusInterface, connectionId: string, nodeFilter?: (node: TreeNode<ViewModel>) => boolean) {
|
||||
this.updateSource = emitter
|
||||
this.connectionId = connectionId
|
||||
|
||||
@@ -12,9 +12,9 @@ export class TreeNode<ViewModel> {
|
||||
public collapsed = false
|
||||
public messages: number = 0
|
||||
public lastUpdate: number = Date.now()
|
||||
public onMerge = new EventDispatcher<void, TreeNode<ViewModel>>(this)
|
||||
public onEdgesChange = new EventDispatcher<void, TreeNode<ViewModel>>(this)
|
||||
public onMessage = new EventDispatcher<Message, TreeNode<ViewModel>>(this)
|
||||
public onMerge = new EventDispatcher<void, TreeNode<ViewModel>>()
|
||||
public onEdgesChange = new EventDispatcher<void, TreeNode<ViewModel>>()
|
||||
public onMessage = new EventDispatcher<Message, TreeNode<ViewModel>>()
|
||||
public isTree = false
|
||||
|
||||
private cachedPath?: string
|
||||
@@ -99,6 +99,21 @@ export class TreeNode<ViewModel> {
|
||||
}
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
for (const edge of this.edgeArray) {
|
||||
edge.target.destroy()
|
||||
}
|
||||
this.edgeArray = []
|
||||
this.edges = {}
|
||||
this.cachedChildTopics = []
|
||||
this.sourceEdge = undefined
|
||||
this.onMerge.removeAllListeners()
|
||||
this.onEdgesChange.removeAllListeners()
|
||||
this.onMessage.removeAllListeners()
|
||||
this.messageHistory = new RingBuffer<Message>(1, 1)
|
||||
this.message = undefined
|
||||
}
|
||||
|
||||
public unconnectedClone() {
|
||||
const node = new TreeNode<ViewModel>()
|
||||
node.message = this.message
|
||||
|
||||
@@ -78,7 +78,7 @@ export class ConnectionManager {
|
||||
}
|
||||
|
||||
class UpdateNotifier {
|
||||
public onCheckUpdateRequest = new EventDispatcher<void, UpdateNotifier>(this)
|
||||
public onCheckUpdateRequest = new EventDispatcher<void, UpdateNotifier>()
|
||||
constructor() {
|
||||
backendEvents.subscribe(checkForUpdates, () => {
|
||||
this.onCheckUpdateRequest.dispatch()
|
||||
|
||||
Reference in New Issue
Block a user