ISSUE: EL 4.1 CacheManager memory leak...

Topics: Caching Application Block , Enterprise Library Core
Nov 29, 2010 at 1:29 PM

I have an application that has a terrible memory leak, I have tracked it down to one line of code that creates an instance of ICacheManager...  CacheManagerFactory.Create.

Below, if I do not manually call cacheMgr.Dispose() in a destructor, I quickly run up 2gig of memory use in a simple test app. (Dispose is not supposed to be used directly)

What is the problem here?


public class LeakLikeCrazy 
{
    public ICacheManager cacheMgr;

    public LeakLikeCrazy()
    {
    	var scs = new SystemConfigurationSource();
	var cmf = new CacheManagerFactory(scs);
	cacheMgr = cmf.Create("XYZ");
    }
}



Nov 30, 2010 at 2:15 AM

In your sample, the ICacheManager is a global variable with in the class so it will only get disposed if there are no more references to the instantiated LeakLikeCrazy object.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 30, 2010 at 3:29 PM

Should this keep references around (this is the sample program that I'm using):

static void Main(string[] args)
{
	int i = 0;
	try
	{
		while (true)
		{
			LeakLikeCrazy svm = new LeakLikeCrazy ();
			Console.WriteLine(String.Format("{0}  :  {1}",i,svm.cacheMgr.Count));
			i++;
			if (i==100) { break; }
		}
	}
	catch(Exception ex)
	{
	}
}


I guess I need to ask:  Should I check anything BEFORE calling CacheManagerFactory.Create()?

Dec 1, 2010 at 3:17 AM
Edited Dec 1, 2010 at 3:21 AM

I guess I should've noticed before.  You should have your LeakLikeCrazy class implement the IDisposable interface.   

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com