controlflow / resharper-heapview

ReSharper Heap Allocations Viewer plugin
MIT License
303 stars 28 forks source link

Assigning new array expressions on read-only spans of byte-sized values does not allocate. #80

Closed teo-tsirpanis closed 1 year ago

teo-tsirpanis commented 3 years ago

See https://github.com/dotnet/roslyn/pull/24621. The plugin currently displays an allocation on the new keyword:

image

controlflow commented 2 years ago

Note to self: works for byte-sized enums as well

using System;
public class C {
    public int M() {
        ReadOnlySpan<E> xs = new E[] { }; // empty span
        ReadOnlySpan<E> ys = new E[] { E.A };
        ReadOnlySpan<E> zs = new E[] { E.A, E.A, E.A };
        return xs.Length + ys.Length + zs.Length;
    }
}

enum E : byte { A }
controlflow commented 1 year ago

Thanks for reporting! Fix will be available in the next plugin release