What happens to the memory allocated on my local variable

39 Views Asked by At

Below is my sample method:

private async Task<Model[]> GetModels()
{
   var toProcess = new List<Model>();
   toProcess.Add(new Model());
   return toProcess.ToArray();
}

What will happen to the toProcess object memory? will it get reclaimed by GC as toProcess.ToArray() will make of copy of elements?

I do not find how to verify this memory is reclaimed by GC using diagnostics tool in VS2022. I verified that object allocation tool is always showing this model[] allocation is happening not sure it is getting disposed/reclaimed.

0

There are 0 best solutions below