HAA0502 Explicit new reference type allocation

≯℡__Kan透↙ 提交于 2019-12-11 16:08:54

问题


I have ASP.Net Core 2.1, C# application. I am using Clr Heap Allocation Analyzer

https://marketplace.visualstudio.com/items?itemName=MukulSabharwal.ClrHeapAllocationAnalyzer

One of the methods looks as below

Ex#1

public void ConfigureServices(IServiceCollection services) {

services.AddSingleton<IPocoDynamo>(serviceProvider => {
    var pocoDynamo = new PocoDynamo(serviceProvider.GetRequieredService<IAmazonDynamoDB>());
    pocoDynamo.SomeMethod();
    return pocoDynamo;
});

}

Ex.#2

public async Task<EventTO> AddEvent(EventTO eventObj)
{
  try
    {       
      throw new Exception("Error!");
    }
 catch (Exception ex)
 {
   Logger.Log(ex, eventObj);
   return null;
  }
}

I am using DI throughout the app. But wherever the analyzer is finding new keyword thing, it is warning as

HAA0502 Explicit new reference type allocation

Also wherever Lambda expression is used, it is warning as (like in ex#1)

Warning HAA0301 Heap allocation of closure Captures:

What is causing this & how to address this?

Thanks!

来源:https://stackoverflow.com/questions/58138603/haa0502explicit-new-reference-type-allocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!