Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafePack和ConcatSafePack这两个函数有内存泄漏的问题 #59

Open
klkucan opened this issue Aug 21, 2020 · 2 comments
Open

SafePack和ConcatSafePack这两个函数有内存泄漏的问题 #59

klkucan opened this issue Aug 21, 2020 · 2 comments

Comments

@klkucan
Copy link

klkucan commented Aug 21, 2020

用的lua profiler作为分析工具,发现SafePack和ConcatSafePack这两个函数出现内存不停的增加的问题

@snuc
Copy link

snuc commented Sep 28, 2020

不是内存泄漏,这两个函数会创建table,分配内存
Bind和Broadcast使用频繁的项目估计要吐血

@dengxuhui
Copy link

dengxuhui commented Jul 21, 2021

local emptyPack = { n = 0 }
-- 解决原生pack的nil截断问题,SafePack与SafeUnpack要成对使用
function SafePack(...)
    local n = select('#', ...)
    if n <= 0 then
        return emptyPack
    else
        local params = { ... }
        params.n = n
        return params
    end
end

-- 解决原生unpack的nil截断问题,SafePack与SafeUnpack要成对使用
function SafeUnpack(safe_pack_tb)
    if safe_pack_tb == emptyPack then
        return nil
    else
        return unpack(safe_pack_tb, 1, safe_pack_tb.n)     
    end
end

目前我用的这种方式处理,也只能说缓解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants