Closed tkkcc closed 2 months ago
Well, static
implies a lifetime of 'static
(i.e. extending to after the program is terminated), so they cannot be dropped, even if there were technical means to do so.
There are also other target-specific reasons why libraries might "fail" to unload cleanly. For example MacOS will not release a DSO if it has thread locals in it.
So if you require that memory is not leaked, using anything related to dlopen
and friends is fundamentally incompatible with the requirements. Your best alternative would be to run the plugin as a separate process or rely on something like WebAssembly and wasmtime.
Hi, i am trying to implement a plugin framework, that each plugin can update(via network) and reload itself without process restart. Currently, i fail to achieve this with libloading, because static variables in plugin are not freed on reload. I wonder if it is expected, and is there any solution(still using libloading).
To reproduce: The guest has 1GB static. The host keeps reloading guest. Then host memory usage keeps growing and gets killed finally.
plugin code:
full demo: https://github.com/tkkcc/libloading_memory_leak_test