Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating TextView with custom font causes heavy work to font cache

Tags:

android

I have a TextView for which i register the following animation:

mScaleAnimation = new ScaleAnimation(1f, 1.2f, 1f, 1.2f,
            mReferenceTextView.getWidth() / 2, mReferenceTextView
                    .getHeight() / 2);
    mScaleAnimation.setRepeatCount(Animation.INFINITE);
    mScaleAnimation.setRepeatMode(Animation.REVERSE);
    mScaleAnimation.setDuration(500);

It works fine and looks really cool :)

My only concern is the following: When i look at logcat, it is totally unusable since as long as the animation ist running, i keep getting these logs over and over multiple times a second :(

06-20 17:50:05.555: DEBUG/skia(14179): purging 213K from font cache [7 entries]
06-20 17:50:05.750: DEBUG/skia(14179): purging 196K from font cache [7 entries]
06-20 17:50:05.870: DEBUG/skia(14179): purging 202K from font cache [8 entries]
06-20 17:50:05.995: DEBUG/skia(14179): purging 190K from font cache [8 entries]

The TextView uses a custom font/typeface (which is in otf format).

Any ideas what causes that heavy work for the font cache?

like image 720
Goddchen Avatar asked Nov 14 '22 21:11

Goddchen


1 Answers

I believe that your cache is getting killed because you are generating tons of TypeFace objects. I'm guessing that this is on a pre ICS release? There is a bug that holds TypeFaces and does not free it up correctly. So when your animating, it keeps creating new objects for each position and they are leaked and never cleaned up.

I found someone's suggestion to create a TypeFace cache with a HashMap. You can check this post out for more details. Custom fonts and XML layouts (Android)

like image 162
Frank Sposaro Avatar answered Jan 08 '23 01:01

Frank Sposaro