On 15.06.2020 15:00, Gabriel Ivăncescu wrote:
Modules must keep refs to the script engine, because the script is closed only when the last non-detached module is released, even if the control is not held anymore. put_Language, however, still releases the engine.
While I agree that we need to change how release_script_engine() works for modules, this doesn't seem right. There is likely a circular dependency between script engine and script host because script host implements IActiveScriptSite. This is fine, because script control guarantees that it will close script engine at some point, breaking the cycle. With your patch, you depend on ref count to close the engine, so in practice it will leak. See the attached hack for a quick test. It passes on Windows and unpatched Wine.
I think that it may be a good idea to just store number of modules alive in script host (maybe even move it from control). You'd then change release_script_engine to something like:
void detach_script_module(ScriptHost *host)
{
if(--host->module_count) return;
// code closing the engine
}
Thanks,
Jacek