java - 获取Android LRUCache当前使用的内存

标签 java android caching memory android-lru-cache

为了进行测试,我想查看 LRU 缓存当前使用了多少 kB/MB。我将总大小设置为 4096。

有没有这样的函数:

public LruCache<String, Bitmap> myCache;
...
...
println(myCache.getUsedAmount());

println(myCache.getAvailabeSpace());

最佳答案

看看Documentation .

如果您不覆盖 sizeOf(K,V),则使用 size() 应该可以正常工作:

For caches that do not override sizeOf(K, V), this returns the number of entries in the cache. For all other caches, this returns the sum of the sizes of the entries in this cache.

您还可以浏览所有条目并检查它们的大小。

关于java - 获取Android LRUCache当前使用的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31646922/

相关文章:

android - 尝试构建共享元素 Lollipop 过渡时过渡名称为空

android - 带有按钮的自定义 View 实现 OnGestureListener

缓存使用、空间局部性和延迟

java - 内部类或单独类

java - 引用数组构造函数

android - Gps 状态启用/禁用广播接收器

.net - 是否有任何模式或实践可以在 .NET 中以非侵入式方式将调试/日志代码引入现有算法?

C# 相当于 Java PushbackReader 的 unread()

java - 如何在 hibernate 中从父表检索子表记录?

c# - memcached - 与 C# asp.net 应用程序一起使用