2013-10-16 14 views
-1

我對Bitmap.createBitmap()的調用總是會導致gc_for_alloc。 下面是代碼:當我調用Bitmap.createBitmap()時如何避免gc_for_alloc?

if (theFinger.isTheSaveFlag()) 
{ 
    theBackGroundBuffer.position(0); 
    gl.glReadPixels(0, 0, theBackGroundWidth, theBackGroundHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, theBackGroundBuffer); 
    theBackGroundBuffer.position(0); 
    theBackGroundBuffer.get(theBackGroundPixel); 
    theBackGroundTexture.dispose(); 
    theBackGround.recycle(); 
    theBackGround = Bitmap.createBitmap(theBackGroundPixel, theBackGroundWidth, theBackGroundHeight, Bitmap.Config.ARGB_8888); 
    theBackGroundTexture.load(theBackGround); 
} 

有人能告訴我爲什麼嗎?

+0

logcat中的'GC_FOR_ALLOC'消息是正常的。當新內存分配需要內存時,垃圾收集器正在完成其工作。你面臨的具體問題是什麼? – laalto

回答

0

在android中,它總是調用垃圾回收器來收集和刪除內存中未使用的資源,這就是爲什麼它會打印gc_for_alloc消息,該消息顯示未使用的資源將被刪除,併爲需要它的其他資源分配空間。

特別是當您對圖像進行操作並在內存中加載大量圖像時需要調用它,這需要更多空間才能加載。

+0

那麼有沒有辦法避免這個問題呢? – user2884920

+0

這不是問題,它的android的垃圾收集器的行爲。 – GrIsHu

相關問題