So I have a stateless Asp.Net Core REST Web API that seems to have a memory leak... which seems strange to me, but the evidence is pretty compelling.
This is a screenshot of my Azure portal showing the RAM slowly going up.
Now my API is pretty standard... CRUD, lots of data retrieval... not a lot of crazy logic or anything, but it gets a good amount of traffic (about 17 requests per second on average). Eventually the server gets to the point where I have to restart it so that the memory is released.
Below is a typical Save method...
Again, the API is stateless so I don't really cache or hold onto any data... just do what I gotta do and give back the data.
Thoughts?
[HttpPost]
public IActionResult Save([FromBody]QuizViewModel quiz)
{
if (ValidateAdmin() == null)
return StatusCode(401);
try
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
Quiz dbQuiz = null;
if (quiz.ID == new Guid())
{
LogInfo("Saving new quiz: Name [" + quiz.Name + "]");
// new
dbQuiz = new Quiz();
dbQuiz.ID = Guid.NewGuid();
dbQuiz.CreatorID = quiz.CreatorID;
dbQuiz.CreateDate = DateTime.UtcNow;
_quizRepository.Add(dbQuiz);
}
else
{
LogInfo("Updating quiz: ID [" + quiz.ID + "], Name: [" + quiz.Name + "]");
// update
dbQuiz = _quizRepository.GetSingle(x => x.ID == quiz.ID, y => y.Questions);
dbQuiz.UpdateDate = DateTime.UtcNow;
dbQuiz.UpdaterID = quiz.CreatorID;
}
_quizRepository.ManageQuestions(dbQuiz, quiz.Questions);
dbQuiz.Name = quiz.Name;
dbQuiz.LessonID = quiz.LessonID;
dbQuiz.Instructions = quiz.Instructions;
dbQuiz.ImagePath = quiz.ImagePath;
dbQuiz.VideoPath = quiz.VideoPath;
_quizRepository.Commit();
quiz = Mapper.Map<Quiz, QuizViewModel>(dbQuiz);
CreatedAtRouteResult result = CreatedAtRoute("Save", new { controller = "Quiz", ID = quiz.ID }, quiz);
LogInfo("Quiz saved: ID [" + dbQuiz.ID + "]");
return new OkObjectResult(result);
}
catch (Exception ex)
{
HandleError(ex);
return BadRequest(ex);
}
}