Clear LRUCache in background.

pull/1/head
Matthew Chen 7 years ago
parent ebcc435c9f
commit 63b6276c25

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "DebugUIContacts.h" #import "DebugUIContacts.h"
@ -1164,7 +1164,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(count > 0); OWSAssert(count > 0);
OWSAssert(batchCompletionHandler); OWSAssert(batchCompletionHandler);
DDLogDebug(@"createRandomContactsBatch: %zd", count); DDLogDebug(@"createRandomContactsBatch: %zu", count);
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) { if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
@ -1219,7 +1219,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
DDLogError(@"Saving fake contacts: %zd", contacts.count); DDLogError(@"Saving fake contacts: %zu", contacts.count);
NSError *saveError = nil; NSError *saveError = nil;
if (![store executeSaveRequest:request error:&saveError]) { if (![store executeSaveRequest:request error:&saveError]) {

@ -43,12 +43,22 @@ public class LRUCache<KeyType: Hashable & Equatable, ValueType> {
selector: #selector(didReceiveMemoryWarning), selector: #selector(didReceiveMemoryWarning),
name: NSNotification.Name.UIApplicationDidReceiveMemoryWarning, name: NSNotification.Name.UIApplicationDidReceiveMemoryWarning,
object: nil) object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(didEnterBackground),
name: NSNotification.Name.OWSApplicationDidEnterBackground,
object: nil)
} }
deinit { deinit {
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
@objc func didEnterBackground() {
SwiftAssertIsOnMainThread(#function)
clear()
}
@objc func didReceiveMemoryWarning() { @objc func didReceiveMemoryWarning() {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)

Loading…
Cancel
Save