Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unbounded memory usage #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ios/Classes/CachingStreamHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class CachingStreamHandler<T>: NSObject, FlutterStreamHandler {
private let cacheSemaphore = DispatchSemaphore(value: 1)

func add(_ taskId: String, _ value: T) {
cacheSemaphore.wait()
cache[taskId] = value
cacheSemaphore.signal()

if let sink = eventSink {
sink(value)
} else {
cacheSemaphore.wait()
cache[taskId] = value
cacheSemaphore.signal()
}
}

Expand All @@ -35,6 +35,7 @@ class CachingStreamHandler<T>: NSObject, FlutterStreamHandler {
for cacheEntry in cache {
events(cacheEntry.value)
}
cache = [:]
cacheSemaphore.signal()

self.eventSink = events
Expand Down
9 changes: 0 additions & 9 deletions ios/Classes/SwiftFlutterUploaderPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
self.resultHandler = CachingStreamHandler()
resultEventChannel.setStreamHandler(resultHandler)

// load entries from database into StreamHandlers, which cache the values.
let resultDatabase = UploadResultDatabase.shared
for map in resultDatabase.results {
if let taskId = map[Key.taskId] as? String {
resultHandler.add(taskId, map)
}
}

self.taskQueue = DispatchQueue(label: "chillisource.flutter_uploader.dispatch.queue")
super.init()

Expand All @@ -66,7 +58,6 @@ public class SwiftFlutterUploaderPlugin: NSObject, FlutterPlugin {
case "setBackgroundHandler":
setBackgroundHandler(call, result)
case "clearUploads":
UploadResultDatabase.shared.clear()
resultHandler.clear()
progressHandler.clear()

Expand Down
2 changes: 0 additions & 2 deletions ios/Classes/URLSessionUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class URLSessionUploader: NSObject {

delegates.append(EngineManager())

delegates.append(UploadResultDatabase.shared)

self.queue.name = "chillisource.flutter_uploader.queue"

let mainBundle = Bundle.main
Expand Down
112 changes: 0 additions & 112 deletions ios/Classes/UploadResultDatabase.swift

This file was deleted.