Sorry for the vague topic title, but I don't know what's going on so I cannot be clearer right now. Basically, I've noticed the IIS app pool eating huge amounts of memory for an api that we have running.
I have a Web api method that returns a list of customers.
public async Task<IHttpActionResult> GetCustomerList()
{
List<CustomerDTO> dtoCustomers = await customerService.GetCustomers();
return CreatedAtRoute("DefaultApi", new { }, dtoCustomers);
}
And here is the GetCustomers method:
public async Task<List<CustomerDTO>> GetCustomers()
{
List<CustomerDTO> lstCustomers = new List<CustomerDTO>();
using (DBContext db = new DBContext())
{
var Customers = await db.Customers.Where(i => i.Deleted == false).OrderBy(i => i.CustomerName).ToListAsync();
foreach (var Customer in Customers)
{
lstCustomers.Add(Mapper.Map<CustomerDTO>(Customer));
}
}
return lstCustomers;
}
The AutoMapper mapping call just news up a instance of the Customer object and sets the values (just name and address) from the entity object.
Each call returns about 100K of data. On each call, the IIS worker process increases it's memory usage by ~50-100MB or more. Running the method several times sends the worker process memory skyrocketing. I did a test whereby I returned an empty list from the GetCustomers() call and the IIS memory usage still keeps going up but at a much slower rate (~80K per call).
So the IIS worker just keeps eating memory too quickly and I'm surprised it's not being garbage collected. I could set a memory limit on the app pool but it would just be recycling over and over again throughout the day.
Does anybody see anything particularly stupid with what I'm doing that is causing this memory consumption? Any thoughts would be appreciated.