[Python.NET] Memory management when embedding python.

Thomas Lundgaard Hansen Thomas.Lundgaard at 3shape.com
Fri Sep 6 12:01:00 EDT 2019


I am embedding Python into a .NET (C#) application. For the purpose of this discussion my code is
like the example given here:
(except that I am working with arrays of a substantial size).

Each of the "dynamic" variables created in that example are of the .NET type PyObject, which is
a disposable type. The code in the example does not call Dispose() on these objects and it would
indeed be very inconvenient to do so.

Whats the best practice here and what considerations went into this design? Can we expect that
the only unmanged resources held by PyObject's are unmanaged memory? (Unless, of course, the
PyObject represents a system resource like a file or network stream).

Has it been considered to use GC.AddMemoryPressure when PyObjects are backed by a large
amount of unmanaged memory?

Thomas Lundgaard Hansen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20190906/128bcaa3/attachment.html>

More information about the PythonDotNet mailing list