niochat/nio

Probable memory leak

mredig opened this issue · 0 comments

This snippet starts at line 189 in AccountStore.swift

    var listenReferenceRoom: Any?

    public func paginate(room: NIORoom, event: MXEvent) {
        let timeline = room.room.timeline(onEvent: event.eventId)
        listenReferenceRoom = timeline?.listenToEvents { event, direction, roomState in
            if direction == .backwards {
                room.add(event: event, direction: direction, roomState: roomState)
            }
            self.objectWillChange.send()
        }
        timeline?.resetPaginationAroundInitialEvent(withLimit: 40) { _ in
            self.objectWillChange.send()
        }
    }

Every time this method is called, listenReferenceRoom is overwritten with a new value and the old one is not removed from listeners. Pretty sure that's a necessary thing, but not an expert in MatrixSDK to know for sure.

Something similar happens on line 151 in the same file, but I believe that method is only called once through the lifetime of the app.