dotnet / TorchSharp

A .NET library that provides access to the library that powers PyTorch.
MIT License
1.37k stars 177 forks source link

Memory leak in string interop #966

Open zgxnet opened 1 year ago

zgxnet commented 1 year ago

TorchSharp uses PinnedArray for string interop, and it does not release the handles explicitly and wishes PinnedArray to release the IntPtr handles when disposing. However, PinnedArray auto-release needs IDisposable to work with, which IntPtr does not implement. I suggest using a dedicated PinnedPtrArray, which is able to release all the handles properly.

NiklasGustafsson commented 1 year ago

@zgxnet -- thank you for noticing this problem. I will take a look at it and see what we can do. You're also welcome to submit a PR with a fix.

zgxnet commented 10 months ago

It seems that the problem is not fixed.

NiklasGustafsson commented 10 months ago

You are right -- it was linked to a PR that I had first imagined would take care of it, but with numerous process crashes, it turned into a much smaller change. The problem remains.