On Tue, Sep 20, 2016 at 4:19 PM, dl l <ldlch...@gmail.com> wrote: > Yes, it's a workaround to set the global variables to None. But My app just > provide a framework for my customers to run python scripts. That's means > the workaround requires my customers to update their python scripts. That > may make them unhappy :(. Is there a workaround in my code C++ side to call > Python C APIs to resolve the memory leak issue? >
Python's import system is fundamentally not designed for what I believe is your use-case here, of running potentially-edited user code. Instead, I suggest keeping 'import' for stable modules that don't get updated without restarting the process, and for the more dynamic code, build something using exec (or PyRun_StringFlags, which I believe is the C equivalent). Object lifetimes will then be entirely under your control. ChrisA -- https://mail.python.org/mailman/listinfo/python-list