MarianoMazzieri

I have a console application, which is a WSE2 Web service with several soap methods. The application starts and the memory usage increases constantly until it reaches to approximately 700MB, then it won't respond anymore. This memory leak happens on Windows 2K3 with SP2 and Framework 1.1, but i can't reproduce it on Windows 2K SP4, weird isn't it

I've reviewed the code in each method to release resources and call Dispose if needed. I have also checked some counters with perfmon and clr_profiler, but no clue of what is causing this behavior. Please help me




Re: Visual C# General Memory Leak

H. Tony

check MemoryFailPoint class,

also forced GC.Collect(); with GC.WaitForPendingFinalizers(); could help too.





Re: Visual C# General Memory Leak

MarianoMazzieri

Thanks for your answer. I've already tried GC.Collect() and GC.WaitForPendingFinalizers() with no luck.

I wouldn't know how to use MemoryFailPoint, since memory is available almost all the time (it takes more than 7 hours to run out of memory) It seems to me like Garbage Collector is blocked for some reason. Any ideas





Re: Visual C# General Memory Leak

H. Tony

I seem to remember GC.WaitForPendingFinalizers() doesn't seem to work but GC.GetTotalMemory(true); works in my own code years ago.

public static long GetTotalMemory (
bool forceFullCollection
)


also I saw a link saying you can call System.GC.RunFinalizers(); to request that finalizers be run on unreferenced objects.




Re: Visual C# General Memory Leak

MarianoMazzieri

Sorry, it dosn't work for me... and System.GC.RunFinalizers() is not avaliable for framework 1.1





Re: Visual C# General Memory Leak

OmegaMan

You need to take a hard look at your code and see where items are being retained, i.e. references holding on to objects. I recommend you implement a dispose on all objects and verify these two things

  1. Release of all references within the object.
  2. Unsubscribe to any events that have been subscribed to. Failure to do this pins the reference and it will never go out of scope.

Also I recommend that you run unit tests on everything behind the Web Service. (The code is broken out in tiers right ) and test the tiers for memory leaks away from the web service. That will make the code more bullet proof and remove the web service as the culprit, or show where the problem is...





Re: Visual C# General Memory Leak

MarianoMazzieri

I've already followed your suggestions but virtual memory is still growing anyway. The strange thing is that this happens on Windows Server 2003, but not on Windows 2000 workstation. I ran the same test in both environments (with same load) and the one on W2K remains stable...

Maybe it's got to do with a service pack. I know there's a Framework 1.1 service pack for Windows Server 2003. Wish me luck.
Gretings.





Re: Visual C# General Memory Leak

jgalley

Interesting that it does not happen on workstation but does on server.

This is not a fix for a leak, but what happens if you set your application on workstation to use server style garbage collection You might also try non-concurrent collection.

Code Block

<configuration>
<runtime>
<gcServer enabled="true"/>
<gcConcurrent enabled="false"/>
</runtime>
</configuration>





Re: Visual C# General Memory Leak

MarianoMazzieri

It made no difference for win2k worksattion, it is stable anyway... What i want is that the Win2003 to behave the same way...





Re: Visual C# General Memory Leak

OmegaMan

MarianoMazzieri wrote:
It made no difference for win2k worksattion, it is stable anyway... What i want is that the Win2003 to behave the same way...


Are you monitering the Private Bytes...that is more of an indicator of a resource leak. If that number grows over time, then yes you have a leak. The CLR will allowcate more memory for an application that what it needs for head room. During that time the application can lesson its memory footprint and the GC will properly clean up the memory. The rub is that the OS will keep the larger size for the application under the premise that the application most likely will request the memory back, so why shrink then expand the footprint against other application. It takes time to do the allocation, and its better to leave it in place for the application to re-use. The footpring may stay for long periods of time if the system is not under stress and the other apps are not clamoring for space.

So long story short, certain memory watches are actually deceiving and do not give the true indicator of what is really going on. This is true with the TaskManager's view of the memory,"this forum is littered with my app doesnt' release memory,. the task manager said...". For it is an amalgamation of differing memory items.

I reccomend that your next step is to identify what is leaking. That may give you a clue to the actual problem....here is some fall reading:





Re: Visual C# General Memory Leak

MarianoMazzieri

Thanks for posting those good advises... Sadly i haven't found the cause of the leak. Even more, i've checked counters for every generation and i've found that total bytes in gen 2 are increasing constantly... but then again, when i run the same test on Windows 2000, it works perfectly fine like clock: no leak.

Is it anything about Windows Server 2003 and framework 1.1 This is making me crazy...