new Span<byte> generates garbage, only when debugger is attached.

KakCAT CAT 21 Reputation points
2020-09-02T14:03:39.137+00:00

I have the following code:

https://pastebin.com/2kDEeUn0

When running it with Ctrl+F5, the GC result is Start=0, End=0

However when running it with F5, the result is Start=0, End=38

Why is this happening and is there any way to avoid this? I'd like to be using Span for some functions but it's tanking my performance when running with a debugger attached (that's 99.9% of time for me)

Tested with both VS2017 and VS2019 (latest)

Thanks!

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
947 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2020-09-03T06:58:28.56+00:00

    Hi KakCATCAT,

    This question is more related to C# garbage collection. Since Microsoft Q&A forum doesn't support C# currently, we suggest you could move to C# msdn forum, and then post a new thread there, the community members will provide dedicated support for you.

    By the way, you could read this reply from stack overflow, maybe it could answer your question.

    Best Regards,
    Dylan

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. KakCAT CAT 21 Reputation points
    2020-09-03T14:45:06.467+00:00

    Thanks for the answer Dylan,

    unfortunately the forum you pointed seems to be archived. The stack overflow answer provides some insight, although it shows no way to fix the problem (there may not be a way). I'll try to search better a place to ask this question.

    Lately it's been increasingly hard to know where to ask questions with VS/C#/.NET