简体   繁体   中英

Memory Allocation / 100% Heap gen2 Fragmentation on Server

I have a .net Windows Service Application which, when started allocates all the existing Memory on the server. After memory profiling I can see, that 90% off the allocated memory is free in the gen 2 Heaps. Fragmentation is at 100%

Running the application via .exe on my workstation dos not produce the same thing. Memory allocation seams normal here.

I've tried to force GC every 5 Seconds to see if there is a problem with the GC. Same problem

My question 1. What could cause memory fragmentation in this case? 2. Is there a way to configure the windows service in a way that makes it behave like my desktop? 3. How would I go and find out what causes the problem?

Thanks alot

The most important difference between a service and a desktop application is the user running the application. Check it from the "Log On" tab on the Services control panel. The default is "Local System Account" which has probably less rights than the desktop user. Change it to your current user and check your application again.

All objects that are about to die and have a finalizer are put into a queue called "finalizer queue". The GC runs the finalizers one-by-one, and if a finalizer is stuck in an infinite loop, the whole GC is blocked. The most visible effect of this is, the never ending increase of memory usage. You can easilt simulate it by adding a code like this.

~MyClass
{
    while (true)
    {
    }
}

First, check all your finalizers. Execution from the local system account may somehow cause an infinite loop somewhere.

Perhaps you don't have any finalizers, then you should do some heuristics on it. Also there is a utility called dotMemory (not free, but have some trial period) that traverses all your heap for objects not freed. It can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM