From 471a30ca3dbb20186494af28ca5f5052150c301e Mon Sep 17 00:00:00 2001 From: Thomas Denney Date: Thu, 15 Sep 2016 09:24:09 +0100 Subject: [PATCH] Minimise memory usage in Mac app directory watcher --- clients/macuploader/Microbit Uploader/DirectoryWatcher.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/macuploader/Microbit Uploader/DirectoryWatcher.m b/clients/macuploader/Microbit Uploader/DirectoryWatcher.m index 66290d67..e33fff81 100644 --- a/clients/macuploader/Microbit Uploader/DirectoryWatcher.m +++ b/clients/macuploader/Microbit Uploader/DirectoryWatcher.m @@ -55,14 +55,16 @@ void callback(ConstFSEventStreamRef streamRef, void * info, size_t numEvents, vo - (void)rescanPathWithEvents:(BOOL)sendEvents { NSArray* downloadFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:nil]; + NSMutableSet* fullSet = [NSMutableSet new]; for (NSString * file in downloadFiles) { + [fullSet addObject:file]; if (![self.knownFiles containsObject:file]) { if (sendEvents) { [self.delegate watcher:self observedNewFileAtPath:file]; } - [self.knownFiles addObject:file]; } } + self.knownFiles = fullSet; } @end