先上日志:
06-26 14:20:56.914 E/filemap ( 6485): mmap(258048,5040412) failed: Out of memory
06-26 14:20:56.914 W/asset ( 6485): create map from entry failed
找到OOM的位置。
罪魁祸首:
Typeface tf = Typeface.createFromAsset(mgr, "fonts/ShouShuti.ttf");
每次文字加载都去获取一下字体样式,估计之后设置就没有释放
selectionPinPaint.setTypeface(tf);
导致OOM;
解决方式:
private static Typeface fontCache;
private static Typeface getFrontType(Context mContext) {
if (fontCache ==null) {
try {
fontCache = Typeface.createFromAsset(mContext.getAssets(),"fonts/frontType.ttf");
}catch (Exception e) {
Log.e("TextUtil--line:584", "fonts/ZITI.ttf not found");
return null;
}
}
return fontCache;
}
增加缓存。
selectionPinPaint.setTypeface(getFrontType(context));
网友评论