【Cocos2d-x】CCLabelTTF在Android上引发的内存泄露问题

前端之家收集整理的这篇文章主要介绍了【Cocos2d-x】CCLabelTTF在Android上引发的内存泄露问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


Logcat信息如下:

11-24 10:57:19.785: D/dalvikvm(17203): GC_CONCURRENT freed 192K,7% free 12749K/13575K,paused 4ms+6ms,total 39ms
11-24 10:57:19.790: V/MediaPlayer-JNI(17203): native_finalize
11-24 10:57:19.790: V/MediaPlayer-JNI(17203): release
11-24 10:57:19.855: D/dalvikvm(17203): GC_CONCURRENT freed 245K,7% free 13055K/13895K,paused 1ms+2ms,total 16ms
11-24 10:57:19.905: D/dalvikvm(17203): GC_CONCURRENT freed 177K,6% free 13381K/14151K,total 18ms
11-24 10:57:19.905: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 6ms
11-24 10:57:19.970: D/dalvikvm(17203): GC_CONCURRENT freed 199K,6% free 13744K/14535K,paused 1ms+1ms,total 22ms
11-24 10:57:19.970: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 9ms
11-24 10:57:20.035: D/dalvikvm(17203): GC_CONCURRENT freed 206K,6% free 14121K/14919K,total 24ms
11-24 10:57:20.035: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 11ms
11-24 10:57:20.130: D/dalvikvm(17203): GC_CONCURRENT freed 254K,6% free 14585K/15431K,total 38ms
11-24 10:57:20.130: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 23ms
11-24 10:57:20.250: D/dalvikvm(17203): GC_CONCURRENT freed 294K,6% free 15121K/16007K,paused 2ms+2ms,total 55ms
11-24 10:57:20.250: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 38ms
11-24 10:57:20.380: D/dalvikvm(17203): GC_CONCURRENT freed 377K,6% free 15806K/16775K,total 35ms
11-24 10:57:20.380: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 22ms
11-24 10:57:20.545: D/dalvikvm(17203): GC_CONCURRENT freed 451K,6% free 16628K/17671K,total 61ms
11-24 10:57:20.545: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 48ms
11-24 10:57:20.790: D/dalvikvm(17203): GC_CONCURRENT freed 546K,7% free 17621K/18759K,total 78ms
11-24 10:57:20.790: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 64ms
11-24 10:57:21.030: D/dalvikvm(17203): GC_CONCURRENT freed 670K,7% free 18841K/20103K,total 77ms
11-24 10:57:21.030: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 63ms
11-24 10:57:21.305: D/dalvikvm(17203): GC_CONCURRENT freed 735K,7% free 20184K/21511K,total 95ms
11-24 10:57:21.305: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 81ms
11-24 10:57:21.595: D/dalvikvm(17203): GC_CONCURRENT freed 733K,6% free 21530K/22855K,total 114ms
11-24 10:57:21.595: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 101ms
11-24 10:57:21.900: D/dalvikvm(17203): GC_CONCURRENT freed 733K,6% free 22874K/24199K,paused 1ms+3ms,total 124ms
11-24 10:57:21.900: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 111ms
11-24 10:57:22.215: D/dalvikvm(17203): GC_CONCURRENT freed 733K,6% free 24218K/25543K,total 138ms
11-24 10:57:22.215: D/dalvikvm(17203): WAIT_FOR_CONCURRENT_GC blocked 124ms
11-24 10:57:22.530: D/dalvikvm(17203): GC_CONCURRENT freed 733K,5% free 25562K/26887K,total 141ms


问题代码


local label = CCLabelTTF:create( “Test” "Arial",21) -- 注意:label的字体size设置为21

cpName:setDimensions(CCSizeMake(20,0)) --但在设置label的大小时宽为20,也就是label的宽比一个字体的宽度小时,就会出现内存泄露。


该bug出现在Cocos2d-x2.1.5,在Cocos2d-x3.0也做了个测试,发现问题在3.x的引擎中已经得到解决

原文链接:https://www.f2er.com/cocos2dx/345976.html

猜你在找的Cocos2d-x相关文章