question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`AccessViolationException` in `TorchTensor.Dispose`

See original GitHub issue

By following memory guide, I added GC.Collect into my code after every epoch. The first such call after an epoch of training crashes with

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at TorchSharp.Tensor.TorchTensor.THSTensor_dispose(IntPtr) at TorchSharp.Tensor.TorchTensor.THSTensor_dispose(IntPtr) at TorchSharp.Tensor.TorchTensor.Dispose(Boolean) at TorchSharp.Tensor.TorchTensor.Finalize()

Repro steps (requires .NET 3.1 Core and C# 9, Windows only):

  1. Clone https://github.com/losttech/Torch.Siren.git
  2. Checkout TorchSharpBugs/315
  3. go to app subfolder
  4. dotnet run path_to_image.jpg

When done from command line, simply crashes with Fatal error. Internal CLR error. (0x80131506) When run from Visual Studio (use Siren.sln at the root), also displayed the stack trace.

Without the call to GC.Collect memory is leaking fast.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
lostmsucommented, Jul 20, 2021

I think I have a fix.

0reactions
NiklasGustafssoncommented, Jul 23, 2021

Fixed with #317 having been merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid System.AccessViolationException during ...
A method ep.libdestroy() invokes Dispose(), where pjsua2PINVOKE.delete_LogWriter(swigCPtr) is. This operation throws an exception: System.
Read more >
System.AccessViolationException: Attempted to read or ...
AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt #742.
Read more >
Torch::from_blob gives access violation in debug mode but ...
The following snippet of code which converts an image into a tensor, results in access violation exception when run in debug mode only....
Read more >
AccessViolationException Class (System)
An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been...
Read more >
Newest 'memory' Questions - Stack Overflow
The application is being used to demonstrate Tensorflow models live through an ... AccessViolationException' occurred in Unknown Module. ... torch.cuda.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found