Re: Diagnosing memory growth
Robert Heller <[email protected]> Tue, 2 May 2023 15:46:48 -0400 (EDT)
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Organization | Deepwoods Software |
| Message-ID | <[email protected]> |
At Tue, 2 May 2023 12:20:31 -0700 Rob McDonald <[email protected]> wrote: > > I have a C++ application wrapped with Swig to Python. > > Some of my users are seeing large and steady memory growth for extended > scripts that make repeated calls to the C++ side of things. > > The non-Swig version of my program also has an embedded scripting > language. If I recreate their Python calls with my scripting language, I > do not see the memory growth. Therefore, I do not initially think the > memory leaks are inherent to my C++ code. > > How can I go about tracking memory use (between a wrapped C++ API, Swig > middle-layer, and Python) from Python? What sorts of diagnostic tools are > there for this? Is your wrapper passing non-scaler objects back and forth between C++ and Python (eg converting things like vectors to lists or lists to vectors, that sort of thing)? If you are you should check to be sure you are including typemaps to "free" and temporary storage being used (freearg typemaps). Also, if your wrappers are wrapping C++ constructors (directly or indirectly), make sure you are also wrapping the destructors. Note: you will probably have to *explicitly* call the destructors -- this might mean that the Python code needs to call a wrapper that includes a call to operator delete() (to match the call to operator new()). You probably won't be getting "free" mamory management when temporary objects go out of scope (like they would in a pure C++ or pure Python program). > > I know that I can not run my C++ with Address Sanitizer or Valgrind under > Python without re-compiling Python with these things enabled (I would > really like to avoid compiling Python). > > Thanks for any suggestions, > > Rob > > _______________________________________________ > Swig-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/swig-user > > -- Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364 Deepwoods Software -- Custom Software Services http://www.deepsoft.com/ -- Linux Administration Services [email protected] -- Webhosting Services