I have a memory leak in my application which uses CTranslate. I’ve been able to narrow the problem down to occurring when I create a CTranslate Translator inside of a PyQt QThread that is created from a QWidget. If I remove the CTranslate Translator and do something else that allocates a large amount of memory there is no leak. If I create the CTranslate Translator from the QWidget with no QThread there is also no leak. If I run the QThread outside of a QWidget there is no leak. The leak only happens with the combo of all three.
My best guess is that there is some bug/me misusing in the combination of Python/Qt/CTranslate memory management. Python uses automatic reference counting memory management, while Qt in native C++ use C++ parent based memory management. On top of that CTranslate uses C++ extensions to Python so it seems like there are a lot of places where the problem could be appearing.
I made an example script demonstrating the leak. To run it you need a CTranslate model and need to provide a path to it in the script. Here’s a Google Drive link where you can download a package for my project that if extracted (its just a renamed .zip archive) has a CTranslate model at
/model. When this script runs it leaks ~5GB of memory.
I also posted this on the Qt Forum.
Thanks for any help!