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

发表于2015-12-26
评论0 2.1k浏览

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, paused 1ms+2ms, 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, paused 1ms+2ms, 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, paused 1ms+2ms, 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, paused 1ms+2ms, 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, paused 1ms+2ms, 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, paused 2ms+2ms, 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, paused 1ms+2ms, 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, paused 2ms+2ms, 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, paused 1ms+2ms, 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, paused 2ms+2ms, 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, paused 1ms+2ms, 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的引擎中已经得到解决。

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引