应用程序不断“从字体缓存中清除”最终由于内存不足而崩溃,android
我刚刚开始构建一个应用程序(它甚至还没有执行任何操作,但显示了一些按钮),当我运行它时,我在 logcat 中收到错误消息: “从字体缓存中获取 193K [23 项]” 一遍又一遍,直到大约一分钟后,应用程序因内存不足而崩溃。我的 3 个按钮是自定义按钮,使用自定义字体。也许字体有问题?
I'm right at the beginning of building an app (which doesn't even do anything yet, but display some buttons) and when I run it, I get the error message in logcat:
"purding 193K from font cache [23 entries]"
over and over, until about a minute later the app crashes due to low memory. My 3 buttons are custom buttons, using a custom font. Problem with the font perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是调用 Typeface.createFromAsset()。
我减少了创建字体工厂的次数,因此每个字体类型都会调用一次 Typeface.createFromAsset() 。
字体工厂将字体保存在哈希图中,这就达到了目的。
我在此链接上找到了解决方案并进行了一些调整:
http://www.levinotik.com/2011/09/22/custom-fonts-in-android-can-cause-issues-heres-how-to -fix-it/
这就是我实现它的方式。
The problem is calling Typeface.createFromAsset().
I've reduced that creating a font factory, so it calls Typeface.createFromAsset() once per font type.
The font factory holds the typeface in a hashmap and that does the trick.
I found the solution on this link and tweaked a little bit:
http://www.levinotik.com/2011/09/22/custom-fonts-in-android-can-cause-issues-heres-how-to-fix-it/
This is how I've implemented it.
通过在活动类中将 Typeface 声明为静态,我已经能够大幅减少这种skia 消息(以及最终的低内存情况)。
即,
这可能看起来有风险,但至少用户可以在我的两个活动之间来回切换,而不会进入低内存状态!
I've been able to drastically reduce this skia message (and eventual low-memory condition) by declaring the Typeface as static within the activity class.
i.e.
this might seem risky, but at least a user can go back and forth between my two activities without entering a low-memory state !