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

Memory leakage in linux using sol:: table #1339

Open
beyondkyq opened this issue Apr 10, 2022 · 0 comments
Open

Memory leakage in linux using sol:: table #1339

beyondkyq opened this issue Apr 10, 2022 · 0 comments

Comments

@beyondkyq
Copy link

beyondkyq commented Apr 10, 2022

SOL_VERSION_STRING "3.2.3"    

C++:

typedef std::shared_ptr<sol::state> lua_state_ptr;
lua_state_ptr pState = nullptr;
sol::table TestFun(sol::this_state s)
{
    sol::state_view lua(s);
    sol::table points = lua.create_table();

    for (int i =0 ;i<100000;++i)
    {
	    sol::table tt= lua.create_table();
	    tt["datetime"] = 1;
	    tt["ms"] = 1;
	    tt["value"] = 1;
	    tt["quality"] = 1;
	    points.add(tt);
    }
    return points;
}
int main()
{
    try
        {
            pState = std::make_shared<sol::state>();
            pState->open_libraries();
            pState->set_function("TestFun", &TestFun0);
            auto varRet = pState->safe_script_file("/root/test.lua");
            if (varRet.valid())
            {
                   pState->script("yun()");  
            }
            pState->collect_garbage();
            pState->collect_garbage();
        }
        catch (sol::error& e)
        {
        }          
        return 0;
}

lua

    function yun()
        local mytable = TestFun()
        print(collectgarbage("count"))
        mytable = nil
        print(collectgarbage("count"))
        collectgarbage("collect")
        collectgarbage("collect")
        print(collectgarbage("count"))
    end

When this code runs on windows, the code executes to return points;, memory will grow to 45M; When executing to pstate - > collect_ garbage(); the memory will be reduced to 10M. However, when running on Linux, the code executes to return points;, The memory will grow to 27M and execute to pstate - > collect_ garbage();the memory will not be reduced. If multiple sol:: state are used in my system, the memory will grow to a very large size. Is my use inappropriate?

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

1 participant