Browse Source

Remove the thread-local cache; it seems to cause massive memory leaks.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
d2f2feb994
  1. 9
      ICSharpCode.NRefactory.CSharp/Resolver/Conversions.cs
  2. 18
      ICSharpCode.NRefactory/Utils/CacheManager.cs

9
ICSharpCode.NRefactory.CSharp/Resolver/Conversions.cs

@ -21,6 +21,7 @@ using System.Collections.Concurrent; @@ -21,6 +21,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Utils;
@ -55,13 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -55,13 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// </summary>
public static Conversions Get(ICompilation compilation)
{
CacheManager cache = compilation.CacheManager;
Conversions conversions = (Conversions)cache.GetThreadLocal(typeof(Conversions));
if (conversions == null) {
conversions = new Conversions(compilation);
cache.SetThreadLocal(typeof(Conversions), conversions);
}
return conversions;
return new Conversions(compilation);
}
#region TypePair (for caching)

18
ICSharpCode.NRefactory/Utils/CacheManager.cs

@ -25,14 +25,14 @@ namespace ICSharpCode.NRefactory.Utils @@ -25,14 +25,14 @@ namespace ICSharpCode.NRefactory.Utils
{
/// <summary>
/// Allows caching values for a specific compilation.
/// A CacheManager consists of two dictionaries: one for shared instances (shared among all threads working with that resolve context),
/// and one for thread-local instances.
/// A CacheManager consists of a for shared instances (shared among all threads working with that resolve context).
/// </summary>
/// <remarks>This class is thread-safe</remarks>
public sealed class CacheManager
{
readonly ConcurrentDictionary<object, object> sharedDict = new ConcurrentDictionary<object, object>(ReferenceComparer.Instance);
readonly ThreadLocal<Dictionary<object, object>> localDict = new ThreadLocal<Dictionary<object, object>>(() => new Dictionary<object, object>(ReferenceComparer.Instance));
// There used to be a thread-local dictionary here, but I removed it as it was causing memory
// leaks in some use cases.
public object GetShared(object key)
{
@ -55,17 +55,5 @@ namespace ICSharpCode.NRefactory.Utils @@ -55,17 +55,5 @@ namespace ICSharpCode.NRefactory.Utils
{
sharedDict[key] = val;
}
public object GetThreadLocal(object key)
{
object val;
localDict.Value.TryGetValue(key, out val);
return val;
}
public void SetThreadLocal(object key, object val)
{
localDict.Value[key] = val;
}
}
}

Loading…
Cancel
Save