u0u0/Cocos2d-Lua-Community

新的音频播放器RDAudio存在内存泄漏

lezard618 opened this issue · 1 comments

测试代码如下

    local printLua = UIImageBox.new("update/public_btn_003.png",function()
    	self:stopAllActions()
		self:runAction(cc.RepeatForever:create(cc.Sequence:create(
				cc.DelayTime:create(0.01),
				cc.CallFunc:create(function ()
					for i = 1, 100 do
                                                local id = math.random() .. os.time()
						audio.playEffectSync(id, “test.ogg”, false)
					end
				end)
			)))
    end,{textParams = {text = "开始", size = 30, color = CoreColor.GENERAL_WORDS, font = HYH3GJ}, NOPLIS = true })
    display.align(printLua, display.LEFT_BOTTOM, 0, 0)
    self:addChild(printLua, 100000)

    local printOjbs = UIImageBox.new("update/public_btn_003.png",function()
		self:stopAllActions()
    	audio.stopAllEffects()
        audio.unloadAllFile()
    end,{textParams = {text = "结束", size = 30, color = CoreColor.GENERAL_WORDS, font = HYH3GJ}, NOPLIS = true })
    display.align(printOjbs, display.LEFT_BOTTOM, 150, 0)
    self:addChild(printOjbs, 100000)

开始和结束按钮,隔1到2秒来回点击,如此重复
就会发现内存不断增长

目前发现的一个解决办法
lua_audio_manual.cpp文件中
lSourceGC方法改成下面这样

static int lSourceGC(lua_State *L)
{
    RDAudioItem *sourceItem = (RDAudioItem *)luaL_checkudata(L, 1, RD_AUDIO_SOURCE);
    if (!sourceItem->deleted) {
        alSourcei(sourceItem->id, AL_BUFFER, 0);
        alDeleteSources(1, &sourceItem->id);
        sourceItem->deleted = true;
    }
    return 0;// number of return values
}

麻烦查看下这个bug,并看下解决方案对不对

u0u0 commented

audio.lua 的内部回收机制确实没有调用stop就__gc,可能导致问题, 加个stop稳妥一点.
02de5f3