简体   繁体   中英

AutoMapper Memory Leak

AutoMapper is taking too much memory. I think it's a memory leak.

I'm using 11.0.1 version in.Net Core 6 framework.

I've profiled the project. Here are a couple of screenshots: 在此处输入图像描述

Memory Usage reaches up to 2 GB by the Web API

Web API 的内存使用量高达 2 GB

Any ideas as to why it is taking this much memory for around 400 mapping classes?

Here's the configuration of AutoMapper being applied from the static IServiceCollection class:

 services.AddAutoMapper( cfg => cfg.AddMaps("WebApi.Common"), typeof(MapperProfile), typeof(VendorProfile));

enter code here

I fixed it by configuring AutoMapper according to the latest documentation.

Below is the code that fixed this issue:

 var mapperConfig = new MapperConfiguration(mc => { mc.AddMaps("WebApi.Common"); mc.AddMaps("WebApi.Core"); }); IMapper mapper = mapperConfig.CreateMapper(); services.AddSingleton(mapper);

Previously, it was configured according to the documentation of an older version of AutoMapper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM