瀏覽代碼

datamodel: Don't try to be smarter than the JVM by calling the garbage collector.

Calling System.gc() or Runtime.getRuntime().gc() is a bad idea for a simple reason: there is no way to know exactly what will be done under the hood by the JVM because the behavior will depend on its vendor, version and options:

Will the whole application be frozen during the call?
Is the -XX:DisableExplicitGC option activated?
Will the JVM simply ignore the call?

An application relying on these unpredictable methods is also unpredictable and therefore broken. The task of running the garbage collector should be left exclusively to the JVM.
eho 7 年之前
父節點
當前提交
5b68a221e9
共有 1 個文件被更改,包括 4 次插入5 次删除
  1. 4 5
      src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

+ 4 - 5
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -245,8 +245,7 @@ public class ThumbnailsCacheManager {
                 }
 
             } catch (OutOfMemoryError oome) {
-                System.gc();
-                Log_OC.e(TAG, "Out of memory -> garbage collector called");
+                Log_OC.e(TAG, "Out of memory");
             } catch (Throwable t) {
                 // the app should never break due to a problem with thumbnails
                 Log_OC.e(TAG, "Generation of thumbnail for " + file + " failed", t);
@@ -467,7 +466,7 @@ public class ThumbnailsCacheManager {
                 }
 
             } catch(OutOfMemoryError oome) {
-                System.gc();
+                Log_OC.e(TAG, "Out of memory");
             } catch (Throwable t) {
                 // the app should never break due to a problem with thumbnails
                 Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t);
@@ -672,7 +671,7 @@ public class ThumbnailsCacheManager {
             } // the app should never break due to a problem with thumbnails
             catch (OutOfMemoryError t) {
                 Log_OC.e(TAG, "Generation of thumbnail for " + mFile.getAbsolutePath() + " failed", t);
-                System.gc();
+                Log_OC.e(TAG, "Out of memory");
             } catch (Throwable t) {
                 // the app should never break due to a problem with thumbnails
                 Log_OC.e(TAG, "Generation of thumbnail for " + mFile.getAbsolutePath() + " failed", t);
@@ -807,7 +806,7 @@ public class ThumbnailsCacheManager {
                 thumbnail = doAvatarInBackground();
 
             } catch(OutOfMemoryError oome) {
-                System.gc(); // todo, does this really make sense?
+                Log_OC.e(TAG, "Out of memory");
             } catch(Throwable t){
                 // the app should never break due to a problem with avatars
                 Log_OC.e(TAG, "Generation of avatar for " + mUsername + " failed", t);