I have a .NET Core 2.2 web API app. It returns rather large chunks of JSON data for a web app that is mostly disconnected from the server.
Throughout the application I return System.Data.DataTable objects from the controllers. A request might be handled like so:
[HttpGet]
public ActionResult<Dictionary<string, object>> Orders(string stuff, DateTime? start, DateTime? end)
{
var ret = new Dictionary<string, object>();
var pending_data = new DataTable();
using (SqlCommand cmd = new SqlCommand("select stuff from stuff", connection)) {
using (SqlDataReader rdr = cmd.ExecuteReader()) {
pending_data.Load(rdr);
}
}
ret.Add("pending_orders", pending_data);
return Ok(ret);
}
Will returning DataTables like this create resource leakage? I'm testing right now and the memory usage seems higher than I anticipated. I may have to write some test code that manually calls the GC to see what the baseline is after each request.