In my project all the data fetched from database is compressed using GzipCompression. I am facing outof memory exception only when I am fetching data from the table with code ="XYE01" which have 315 records.
I tried GC.Collect() and GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; before compressing data still I am facing the issue
[AttributeUsage(AttributeTargets.Method)]
public class GZipCompressionAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Response != null)
{
try
{
var content = actionExecutedContext.Response.Content;
var bytes = content != null ? content.ReadAsByteArrayAsync().Result : null;
var zlibbedContent = bytes != null ? GZipCompressionHelper.Compression(bytes) : new byte[0];
actionExecutedContext.Response.Content = new ByteArrayContent(zlibbedContent);
actionExecutedContext.Response.Content.Headers.Remove("Content-Type");
actionExecutedContext.Response.Content.Headers.Add("Content-Encoding", "gzip");
actionExecutedContext.Response.Content.Headers.Add("Content-Type", "application/json");
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, string.Format("Cannot compress on query: {0}.", actionExecutedContext.Request.RequestUri.PathAndQuery), ex);
}
}
base.OnActionExecuted(actionExecutedContext);
}
}
#region publicMethods
// GET api/RequiredStartingValue/GetRequiredStartingValues?code=
[GZipCompression]
[HttpGet, CacheOutput(NoCache = true)]
[UnitOfWorkAction(ReadUncommitted = true)]
public IHttpActionResult GetRequiredStartingValues(string code)
{
List<StartingValue> requiredStartingValues = _startingValuesRepository.GetRequiredStartingValues(customerCode);
return Ok(requiredStartingValues );
}
#endregion
How to increase the memory? Other tables where 900 rows coming is also working fine but with 315 rows it is throwing out of memory exception I am not able to understand.
Please provide me some suggestions as I am new to WebAPI and Database fetching I am unable to understand the root cause.
Thanks, Nagasree.