Hello!
I’m using Dialogue System, and I’ve noticed that after exiting and loading a saved game, many unrelated assets remain loaded in memory. These include Texture, SpriteAtlas, DialogueDatabase instances, etc. After some investigation, I found that even after exiting the saved game and unloading the scene, some static dictionaries in the Lua environment are still holding references to these objects.
I tried calling methods similar to InitStaticVariables in the LuaInterpreter and Lua classes during unloading. As a result, those assets were no longer referenced and could be unloaded properly. (Calling DatabaseManager.Clear alone did not have this effect.)
Did I miss anything? If calling methods like InitStaticVariables is the correct approach, could you consider adding some similar public methods? Thank you!
How to Reset the Lua Environment?
Re: How to Reset the Lua Environment?
Hi,
Depending on what you want to clear, you can call DialogueManager.RemoveDatabase() to remove databases from memory that you added during play, or call SaveSystem.ResetGameState() to clear the saved game data in memory -- however, you shouldn't need this latter method if you're loading a saved game, since that will also clear and reload the saved game data.
Depending on what you want to clear, you can call DialogueManager.RemoveDatabase() to remove databases from memory that you added during play, or call SaveSystem.ResetGameState() to clear the saved game data in memory -- however, you shouldn't need this latter method if you're loading a saved game, since that will also clear and reload the saved game data.
Re: How to Reset the Lua Environment?
Thank you for your response regarding saving and loading. That said, I wanted to point out that the main issue seems to occur after calling DatabaseManager.Reset, where some old references in the Lua environment are not fully cleared.
As described earlier, these lingering references are only completely cleaned up when methods similar to InitStaticVariables in the LuaInterpreter and Lua classes are called.
As described earlier, these lingering references are only completely cleaned up when methods similar to InitStaticVariables in the LuaInterpreter and Lua classes are called.
Re: How to Reset the Lua Environment?
I think this issue could be considered a bug.
Re: How to Reset the Lua Environment?
I agree. I'll address this in version 2.2.56.
Re: How to Reset the Lua Environment?
Looking forward to your fix!
Maybe some internal functions in Dialogue System are not being unregistered from Lua?
In my case, calling InitStaticVariables resolves the issue, since I also unregister all the Lua functions I registered when unloading the scene. However, other users might still want to use Lua functions after a scene has been unloaded.
In any case, this bug needs to be handled carefully — or perhaps there could be a method that allows users to manually reset the Lua environment when needed.
Maybe some internal functions in Dialogue System are not being unregistered from Lua?
In my case, calling InitStaticVariables resolves the issue, since I also unregister all the Lua functions I registered when unloading the scene. However, other users might still want to use Lua functions after a scene has been unloaded.
In any case, this bug needs to be handled carefully — or perhaps there could be a method that allows users to manually reset the Lua environment when needed.