簡體   English   中英

我的Android應用在Android 5.0上占用50MB內存

[英]My android app takes 50MB memory on Android 5.0

我正在Android 4.1.1上開發我的android應用,正在使用listview顯示100張圖像,正在使用Universal Image Loader顯示所有圖像。

我的應用在Android 4.1.1上使用了大約20MB,當加載更多圖片時,它可以達到30MB,這是可以接受的。 不幸的是,當我在Android 5.0上測試我的應用程序時,它使用了大約40MB的內存,而當它加載更多圖像時,它占用了55MB的空間,這使我的應用程序運行起來很慢。

這是我定義通用映像加載程序選項的方式:

    private DisplayImageOptions options = new DisplayImageOptions.Builder()
            .delayBeforeLoading(100)
            .resetViewBeforeLoading(true)
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .postProcessor(null)
            .showImageOnFail(R.drawable.empty_loading)
            .showImageForEmptyUri(R.drawable.empty_loading)
            .considerExifParams(true)
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565) //makes image smaller
//            .displayer(new FadeInBitmapDisplayer(300, true, true, true)) //comment out this line, then flickering is gone
            .build();

我不知道為什么會發生,請幫忙!

提前致謝。

好的,這不是這個問題的答案。 我根據您的評論進行編碼。 如何獲取應用程序緩存大小:

File cacheDirectory = mContext.getCacheDir();
long size = 0;
File[] files = cacheDirectory.listFiles();
for (File f:files) {
    size = size+f.length();
}

看看在豆形軟糖和lolipop中其大小是否不同

問題很明顯,如果加載不正確,加載100張圖像將導致內存問題。

對於高分辨率圖像,情況會越來越糟,最好使用可以為您管理此任務甚至緩存的庫,並嘗試降低分辨率。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM