You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the technique described here to convert a Numpy ndarray to .Net Array and use the resulting array in C# code. However, the array is not garbage collected, as the Python interpreter keeps a reference on the array (Python.Runtime.CLRObject).
I have included an example below, where each step in the iteration increases the memory usage by about 8MB, since the old arrays are not garbage collected.
I have tried using the Dispose() method on the array, and forcing the Python garbage collector (as suggested in other issues), but to no avail. I have also tried 100 other things, but there is no to re-iterate all the failures here.
Not sure where to go from here. Any suggestions are welcome!
I don't see any code in your example, that would necessarily cause C# garbage collector to run. .NET does not immediately deallocate objects, which have no references to them. It only does so under memory pressure.
Ok, maybe this is just due to my inexperience with the .Net garbage collector. It seemed weird to me that the program is allowed allocate many GBs of memory in chunks of 8MB to keep objects that are not referenced. The garbage collector does eventually get around to clean up.
Environment
Details
I use the technique described here to convert a Numpy ndarray to .Net Array and use the resulting array in C# code. However, the array is not garbage collected, as the Python interpreter keeps a reference on the array (Python.Runtime.CLRObject).
I have included an example below, where each step in the iteration increases the memory usage by about 8MB, since the old arrays are not garbage collected.
I have tried using the Dispose() method on the array, and forcing the Python garbage collector (as suggested in other issues), but to no avail. I have also tried 100 other things, but there is no to re-iterate all the failures here.
Not sure where to go from here. Any suggestions are welcome!
Example code
C# code
Program.cs
:Python code
testmodule.py
:The text was updated successfully, but these errors were encountered: