注意问题php
如何计算Bitmap占用内存java
1.1 如何计算占用内存android
1.2 上面方法计算内存对吗c++
我看到好多博客都是这样计算的,可是这样算对吗?有没有哥们试验过这种方法正确性?我以为看博客要对博主表示怀疑,论证别人写的是否正确。更多详细能够看个人GitHub:https://github.com/yangchong211git
@Nullable public static Bitmap decodeResourceStream(@Nullable Resources res, @Nullable TypedValue value, @Nullable InputStream is, @Nullable Rect pad, @Nullable Options opts) { validate(opts); if (opts == null) { opts = new Options(); } if (opts.inDensity == 0 && value != null) { final int density = value.density; if (density == TypedValue.DENSITY_DEFAULT) { opts.inDensity = DisplayMetrics.DENSITY_DEFAULT; } else if (density != TypedValue.DENSITY_NONE) { opts.inDensity = density; } } if (opts.inTargetDensity == 0 && res != null) { opts.inTargetDensity = res.getDisplayMetrics().densityDpi; } return decodeStream(is, pad, opts); }
正确说法,这个注意呢?计算公式以下所示github
1.3 一个像素占用多大内存技术博客大总结面试
Bitmap.Config用来描述图片的像素是怎么被存储的?算法
如何理解recycle释放内存问题?segmentfault
图片加载到内存其实有两部分数据,这是为什么?技术博客大总结数组
查看源码以下所示
如何在不压缩图片的状况下加载高清大图?
自定义可拖动的显示高清大图的View技术博客大总结
为减小流量消耗,可采用缓存策略。经常使用的缓存算法是LRU(Least Recently Used):
核心思想:当缓存满时, 会优先淘汰那些近期最少使用的缓存对象。主要是两种方式:
大概过程以下?技术博客大总结
若是缓存满了的话,什么方法来管理移除最近最少使用的item和添加新的item?
trimToSize()方法,删除最年长的条目,直到剩余条目的总数达到或低于请求的大小
public void trimToSize(int maxSize) { while(true) { Object key; Object value; synchronized(this) { if (this.size < 0 || this.map.isEmpty() && this.size != 0) { throw new IllegalStateException(this.getClass().getName() + ".sizeOf() is reporting inconsistent results!"); } if (this.size <= maxSize || this.map.isEmpty()) { return; } Entry<K, V> toEvict = (Entry)this.map.entrySet().iterator().next(); key = toEvict.getKey(); value = toEvict.getValue(); this.map.remove(key); //计算如今缓存的大小,而后减掉多余的,内部调用的是sizeOf()方法 this.size -= this.safeSizeOf(key, value); ++this.evictionCount; } //若是你想在在咱们的缓存中实现二级缓存,能够实现此方法,源码中是空方法。 this.entryRemoved(true, key, value, (Object)null); } }