From 7c36a7eb49ddbb1b027b6a382e93007d51751aad Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 3 Dec 2022 16:56:23 +0100 Subject: [PATCH] Run Lua GC in every frame --- apps/openmw/mwlua/luamanagerimp.cpp | 4 ++++ docs/source/reference/modding/settings/lua.rst | 11 +++++++++++ files/settings-default.cfg | 3 +++ 3 files changed, 18 insertions(+) diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 220655fbb0..dce51454ec 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -132,6 +132,10 @@ namespace MWLua void LuaManager::update() { static const bool luaDebug = Settings::Manager::getBool("lua debug", "Lua"); + static const int gcStepCount = Settings::Manager::getInt("gc steps per frame", "Lua"); + if (gcStepCount > 0) + lua_gc(mLua.sol(), LUA_GCSTEP, gcStepCount); + if (mPlayer.isEmpty()) return; // The game is not started yet. diff --git a/docs/source/reference/modding/settings/lua.rst b/docs/source/reference/modding/settings/lua.rst index b0fd88fe30..1aca9fec0f 100644 --- a/docs/source/reference/modding/settings/lua.rst +++ b/docs/source/reference/modding/settings/lua.rst @@ -87,3 +87,14 @@ If exceeded (e.g. because of an infinite loop) the function will be terminated. This setting can only be configured by editing the settings configuration file. +gc steps per frame +------------------ + +:Type: integer +:Range: >= 0 +:Default: 100 + +Lua garbage collector steps per frame. The higher the value the more time Lua runtime can spend on freeing unused memory. + +This setting can only be configured by editing the settings configuration file. + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 6f672a65b4..6a4800b47a 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1158,6 +1158,9 @@ log memory usage = false # If exceeded (e.g. because of an infinite loop) the function will be terminated. instruction limit per call = 100000000 +# Lua garbage collector steps per frame. +gc steps per frame = 100 + [Stereo] # Enable/disable stereo view. This setting is ignored in VR. stereo enabled = false