2016-01-21 80 views
3

我想計算SDWebImage佔用的當前內存大小(不是SDWebImage的最大大小)。在應用程序使用過程中,我需要通過SDWebImage緩存對象跟蹤當前的RAM分配情況。SDWebImage緩存對象的大小

基本上我想在NSCache對象中計算所有圖像(當時出現)的大小。

我該怎麼做?

謝謝。

回答

1

意思此,從SDWebImageCache.h採取:

/** 
    * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. 
    */ 

    @property (assign, nonatomic) NSUInteger maxMemoryCost;` 

字節然後總數是在存儲器中保存的像素數*每像素字節,在這種情況下的數4字節/象素

+0

緩存(在給定時間點)消耗的RAM數量(以字節/ KB爲單位)。 – Karthik207

+0

從maxMemoryCost中,我如何計算分配的內存? – Karthik207

+0

它總是4字節/像素?你如何確定每個像素的字節數? – Karthik207

5

我認爲這將使用給定的代碼返回內存緩存。

使用getSize功能SDImageCache.h。它在內存緩存中返回。

[[SDImageCache sharedImageCache] getSize]; 

按照SDWebImage瞭解更多詳情。

+0

[[SDImageCache sharedImageCache] getSize]給出的磁盤高速緩存大小不是內存高速緩存。 – Karthik207

+0

僅供參考,檢索的大小以字節爲單位。 –