Question

I recently wrote a small service that handles high amounts of throughput (on the order of 60+ million requests per day) and it is encountering memory issues. At first, I looked through all of the usual suspects convinced that it had to be something I wrote as opposed to something to do with the very useful very performance-oriented ServiceStack libraries. Upon using windbg to !dumpheap -stat on the production server, however, I discovered to my surprise that the vast majority of objects in memory were System.WeakReference types with !gcroots pointing to ServiceStack's Funq container.

I do not even use an IoC'ed data structure in my service, so I was wondering why this is happening? Am I initializing something incorrectly? My apphost initialize class just calls the base constructor with the assembly and name information, I do not override the Configure method at all.

public SvcName() : base("SvcName", typeof(SvcName).Assembly) { }

I read elsewhere that the System.WeakReference objects are often inserted by .NET in rare instances due to the Visual Studio compiling the binaries having the "Edit and Continue" debugging option on, but turning it off in my VS has no effect (presumably because the SS binaries are already compiled and just referenced in my project).

Has anyone else ever had this issue?

Was it helpful?

Solution

WeakReference is used in Funq to track IDisposable's that's stored in a WeakReference Stack of disposables as seen here. Basically Funq tracks every IDisposable WeakReference created so they can all be disposed of when the Container is disposed.

I would first look at whether you could reduce your use of IDisposable instances (e.g. using more singletons), otherwise try modifying the Funq source code to use Stack<IDisposable> instead of a Stack<WeakReference> and let me know if this resolves your issue, if it does I can include an opt-in option in ServiceStack to use Stack<IDisposable> instead of Stack<WeakReference>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top