App运行,logcat日志不断输出purging 191k from font cache这样的消息

解决方案 »

  1.   

    logcat日志具体如下
    purging 191k from font cache [26 entries]
    purging 191k from font cache [26 entries]
    purging 191k from font cache [26 entries]
    process com.android.deskclock(pid 1046) has died.
    ---no context for glyph 0存在内存泄漏吗?把系统的进程com.android.deskclock都杀死了!!!
      

  2.   

    我的APP用到了SKIA的字库接口,不调这个接口就不会输出上面的logcat日志。看来我封的SKIA字库操作函数存在问题,但就是不清楚问题在那里,我用到的资源都对应进行了释放啊!为什么会这样?我的SKIA字库操作函数也是网上抄过来的,按道理不应该存在问题啊!
      

  3.   

    app keeps 'purging from font cache' and eventually crashes due to low memory,androidhttp://stackoverflow.com/questions/5251608/app-keeps-purging-from-font-cache-and-eventually-crashes-due-to-low-memory-an
      

  4.   

    看来也有人遇到了这个问题了。
    最怕的就是---no context for glyph 0这个了,输出这个后整个APP就全黑了。但重新运行一切又OK了,看来也不是内存不够啊!
      

  5.   

    上一段SKIA下使用字库的代码---我封的跟个类似
    Skia API的简单应用----http://blog.csdn.net/cuiyan0214/article/details/5964739 e)  例程    i )画点、线、圆、文字 #include "SkBitmap.h" #include "SkDevice.h" #include "SkPaint.h" #include "SkRect.h" #include "SkImageEncoder.h" #include "SkTypeface.h" 
    using namespace std; 
    int main() { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config,320,240); bitmap.allocPixels(); SkCanvas canvas(new SkDevice(bitmap)); SkPaint paint; // draw points with red. paint.setARGB(255, 255, 0, 0); paint.setStrokeWidth(4); canvas.drawPoint(40,30, paint); canvas.drawPoint(80,60, paint); canvas.drawPoint(120,90, paint); //draw a line with green. paint.setARGB(255, 0, 255, 0); paint.setStrokeWidth(4); canvas.drawLine(160,10,320,110,paint); //draw a circle with bule. paint.setARGB(255, 0, 0, 255); canvas.drawCircle(80,180,50,paint); //draw text with red SkTypeface *font = SkTypeface::CreateFromFile("simkai.ttf"); if ( font ) { paint.setARGB(255, 255, 0, 0); paint.setTypeface( font ); paint.setTextSize(24); canvas.drawText("HELLO!:)", 8, 200, 180, paint); } SkImageEncoder::EncodeFile("snapshot.png", bitmap,SkImageEncoder::kPNG_Type,100); return 0; } 不知道这里的SkTypeface *font 对像要这么释放,因为跟FONT有关的就是这个对象了。
      

  6.   

    Re: [android-developers] skia / purging [x]k from font cache [y entries] - what does it mean? was Re: Custom Fontshttp://mail.org/message/t6ay2gfrf5igmnfv
      

  7.   

    今天试了一下,把我自己封装的SKIA字库操作函数屏蔽就不会出purging 191k from font cache [26 entries]日志了,难道我封的函数存在问题?明天得好好查查!
    难道是因为SkTypeface *font = SkTypeface::CreateFromFile("simkai.ttf"); 这样的创建函数进行了多次创建的原因?难道要整成全局的并只创建一次?!
      

  8.   

    http://groups.google.com/group/android-developers/browse_thread/thread/15803bc32cfe8b7fAfter seeing this response, I spent some time to figure out exactly what I 
    was doing now that was causing this to appear in the logs so much.  I was 
    puzzled because I wasn't using many styles or colors, the same font, same 
    color.  I turned off alpha blending, and removed all the items I was drawing 
    until I was left with 1, and it was still overloading the cache.  I narrowed 
    it down to doing: 
    canvas.save(); 
    canvas.rotate(rotationAngle, p.x, p.y); // this is the offending line 
    canvas.drawText(text, p.x, p.y, paint); 
    canvas.restore(); 
    If I rotate and then draw text (this is an AR type implementation where the 
    text is rotating with the phone), this is where the font cache fills up, 
    with just 1 static piece of text.  Commenting out the above line doesn't. 
     Even with a large number of text items, NOT rotating the canvas before 
    drawing the text, doesn't fill the cache. 
    This seems kind of strange to me that this would fill the cache, but, is 
    there another way to do this to not fill the cache? 
    On Mon, Jun 20, 2011 at 7:43 PM, Dianne Hackborn <[email protected]>wrote: > Well having it printed every second or so indicates you are pretty severely 
    > thrashing the cache, which can certainly impact performance.  For example 
    > drawing your UI may not be fitting in the cache so each frame you draw 
    > requires re-rendering glyphs back in to the cache.  If that is the case, 
    > look at doing things like reducing the number of distinct font sizes or 
    > families/styles you are using to have less impact on the cache. 
    -- 
    Adam Ratana 
    [email protected]