TorchSharp icon indicating copy to clipboard operation
TorchSharp copied to clipboard

Memory leak in string interop

Open zgxnet opened this issue 2 years ago • 3 comments

TorchSharp uses PinnedArray<IntPtr> 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.

zgxnet avatar Mar 25 '23 05:03 zgxnet

@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.

NiklasGustafsson avatar Mar 27 '23 16:03 NiklasGustafsson

It seems that the problem is not fixed.

zgxnet avatar Nov 19 '23 02:11 zgxnet

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.

NiklasGustafsson avatar Nov 20 '23 17:11 NiklasGustafsson