aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Asp.net Core not Collecting Garbage

Open sebastienros opened this issue 8 years ago • 3 comments

Copied from https://github.com/aspnet/Home/issues/1976

@atpyk commented 10 days ago

Same issue. I have an asp.net webapi backend service. The stacks are asp.net mvc, autofac, automapper, castle.dynamicproxy, entity framework core. All memory will be eaten, then service crash.

Version is 2.1.0

@wanton7 commented 10 days ago

@atpyk Update to 2.1.1. If that doesn't help you should really profile what's keeping that memory. I've used https://www.jetbrains.com/dotmemory/ but there are probably other tools that can do this as well. It can show what's actually allocated in Large Object Heap (LOH).

Are you running in 32bit mode? Because Large Object Heap allocations (bigger than ~85000 bytes) can cause out of memory exceptions in 32bit mode due to fragmentation. You can get over this limit very easily using Dictionary<T, T>. Check this comment https://github.com/aspnet/Home/issues/1976#issuecomment-393833505

If you are running your code in full .Net Framework default behavior is running any cpu code in 32bit mode. You need to uncheck Prefer 32bit from project settings or set some registry setting in your servers registry to default to 64bit.

@atpyk commented 9 days ago

@wanton7 Many thanks. I will try your solutions.

@atpyk commented 22 hours ago

I updated to 2.1.2 and deploy on Microsoft Azure webapp with win-x64, but no effect. @wanton7 dotnetcorememory

@sebastienros commented 22 hours ago

@atpyk please create a memory snapshot (dump_ and analyze it (Visual Studio, MemoScope) to see what object are taking all the memory, or just increasing in count. You can also take two and compare them overtime.

@wanton7 commented 19 hours ago

@atpyk then it sounds like a memory leak. Profile your memory to see what is keeping that memory around like @sebastienros said.

One question, are you even using ASP.NET Core? I read you first comment again and you mention ASP.NET MVC. ASP.NET MVC and ASP.NET Core are two completely different products. These issues and this repo for ASP..NET Core.

Edit: Just from version numbers sounds like you are using ASP.NET Core, but wanted to make sure.

@atpyk commented 17 hours ago

We use .net core MVC. @wanton7 I am doing analyze the memory. Maybe the Castle Dynamic Proxy lead to memory leak. memroy1 memroy2 memroy3 dynamicproxy

sebastienros avatar Aug 10 '18 00:08 sebastienros

@atpyk

Do you want me to continue investigating on your issue or do you think you have reached an understanding of why it behaves like this. Do you want me to get a quick look at how you are using Castle?

sebastienros avatar Aug 10 '18 00:08 sebastienros

@sebastienros I think I have found the root cause that is the incorrect usage for Castle Dynamic Proxy. I have used the Autofac.Extras.DynamicProxy instead. So far, the memory maintained in a normal range, but still need to prove it by long term testing and stress testing.

Thanks.

atpyk avatar Aug 10 '18 01:08 atpyk

Thanks for letting me know. I will close the issue but feel free to reopen if you find out there is still an issue.

sebastienros avatar Aug 10 '18 01:08 sebastienros