Skip to content

Instantly share code, notes, and snippets.

@aliostad
Created October 4, 2013 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliostad/6826806 to your computer and use it in GitHub Desktop.
Save aliostad/6826806 to your computer and use it in GitHub Desktop.
Not disposing MemoryCache results in memory leak
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000000000; i++)
{
var memoryCache = new MemoryCache("sdf"); // leads to memory leak!!!
// WHILE THIS ONE DOES NOT
// var memoryStream = new MemoryStream(new byte[100000]);
Thread.Sleep(1);
}
}
}
@khanziaullah
Copy link

Shouldn't you use MemoryCache.Default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment