浏览代码

clear cache on memory warning, not just on disappear

B. Petersen 2 年之前
父节点
当前提交
d71b4fb320
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. 5 3
      deltachat-ios/Controller/GalleryViewController.swift
  2. 4 0
      deltachat-ios/Extensions/Extensions.swift

+ 5 - 3
deltachat-ios/Controller/GalleryViewController.swift

@@ -97,9 +97,11 @@ class GalleryViewController: UIViewController {
         setupContextMenuIfNeeded()
     }
 
-    override func viewDidDisappear(_ animated: Bool) {
-        // user leaves view and may not come back soon: clearing cache may free a significant amount of memory
-        galleryItemCache = [:]
+    override func didReceiveMemoryWarning() {
+        super.didReceiveMemoryWarning()
+        if !isOnScreen() {
+            galleryItemCache = [:]
+        }
     }
 
     override func viewWillLayoutSubviews() {

+ 4 - 0
deltachat-ios/Extensions/Extensions.swift

@@ -57,6 +57,10 @@ extension UIViewController {
     @objc func dismissKeyboard() {
         view.endEditing(true)
     }
+
+    func isOnScreen() -> Bool {
+        return viewIfLoaded?.window != nil
+    }
 }
 
 extension UIAlertController.Style {