Index: trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
===================================================================
--- trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs	(revision 8600)
+++ trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs	(revision 9195)
@@ -21,4 +21,5 @@
 
 using System;
+using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -31,5 +32,5 @@
   [Item("LookupParameter", "A parameter whose value is retrieved from or written to a scope.")]
   [StorableClass]
-  public class LookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
+  public class LookupParameter<T> : Parameter, IStatefulItem, ILookupParameter<T> where T : class, IItem {
     [Storable]
     private string actualName;
@@ -59,9 +60,31 @@
     }
 
+    private Lazy<ThreadLocal<IItem>> cachedActualValues;
+    private IItem CachedActualValue {
+      get { return cachedActualValues.Value.Value; }
+    }
+
+    private Lazy<ThreadLocal<IExecutionContext>> executionContexts;
+    public IExecutionContext ExecutionContext {
+      get { return executionContexts.Value.Value; }
+      set {
+        if (value != executionContexts.Value.Value) {
+          executionContexts.Value.Value = value;
+          cachedActualValues.Value.Value = null;
+        }
+      }
+    }
+
     [StorableConstructor]
-    protected LookupParameter(bool deserializing) : base(deserializing) { }
+    protected LookupParameter(bool deserializing)
+      : base(deserializing) {
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+    }
     protected LookupParameter(LookupParameter<T> original, Cloner cloner)
       : base(original, cloner) {
       actualName = original.actualName;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter()
@@ -69,4 +92,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name)
@@ -74,4 +99,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name, string description)
@@ -79,4 +106,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name, string description, string actualName)
@@ -84,4 +113,6 @@
       this.actualName = string.IsNullOrWhiteSpace(actualName) ? Name : actualName;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
 
@@ -132,4 +163,5 @@
     }
     protected override IItem GetActualValue() {
+      if (CachedActualValue != null) return CachedActualValue;
       string name;
       // try to get value from context stack
@@ -146,4 +178,5 @@
                           typeof(T).GetPrettyName())
           );
+        cachedActualValues.Value.Value = var.Value;
         return var.Value;
       }
@@ -156,4 +189,6 @@
                         typeof(T).GetPrettyName())
         );
+      cachedActualValues.Value.Value = value;
+
       // try to set value in context stack
       string name;
@@ -175,4 +210,17 @@
     }
 
+    public virtual void InitializeState() {
+    }
+    public virtual void ClearState() {
+      if (cachedActualValues.IsValueCreated) {
+        cachedActualValues.Value.Dispose();
+        cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      }
+      if (executionContexts.IsValueCreated) {
+        executionContexts.Value.Dispose();
+        executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      }
+    }
+
     public event EventHandler ActualNameChanged;
     protected virtual void OnActualNameChanged() {
Index: trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
===================================================================
--- trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs	(revision 8600)
+++ trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs	(revision 9195)
@@ -22,5 +22,4 @@
 using System;
 using System.Drawing;
-using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -33,5 +32,5 @@
   [Item("Parameter", "A base class for parameters.")]
   [StorableClass]
-  public abstract class Parameter : NamedItem, IParameter, IStatefulItem {
+  public abstract class Parameter : NamedItem, IParameter {
     public override Image ItemImage {
       get {
@@ -67,24 +66,7 @@
     }
 
-    private Lazy<ThreadLocal<IItem>> cachedActualValues;
     public IItem ActualValue {
-      get {
-        if (cachedActualValues.Value.Value == null) cachedActualValues.Value.Value = GetActualValue();
-        return cachedActualValues.Value.Value;
-      }
-      set {
-        cachedActualValues.Value.Value = value;
-        SetActualValue(value);
-      }
-    }
-    private Lazy<ThreadLocal<IExecutionContext>> executionContexts;
-    public IExecutionContext ExecutionContext {
-      get { return executionContexts.Value.Value; }
-      set {
-        if (value != executionContexts.Value.Value) {
-          executionContexts.Value.Value = value;
-          cachedActualValues.Value.Value = null;
-        }
-      }
+      get { return GetActualValue(); }
+      set { SetActualValue(value); }
     }
 
@@ -92,6 +74,4 @@
     protected Parameter(bool deserializing)
       : base(deserializing) {
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     protected Parameter(Parameter original, Cloner cloner)
@@ -99,6 +79,4 @@
       dataType = original.dataType;
       hidden = original.hidden;
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     protected Parameter()
@@ -106,6 +84,4 @@
       dataType = typeof(IItem);
       hidden = false;
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     protected Parameter(string name, Type dataType)
@@ -114,6 +90,4 @@
       this.dataType = dataType;
       hidden = false;
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     protected Parameter(string name, string description, Type dataType)
@@ -122,12 +96,4 @@
       this.dataType = dataType;
       hidden = false;
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-    }
-
-    public virtual void InitializeState() { }
-    public virtual void ClearState() {
-      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
 
Index: trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs
===================================================================
--- trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs	(revision 8600)
+++ trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs	(revision 9195)
@@ -21,4 +21,5 @@
 
 using System;
+using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -31,8 +32,9 @@
   [Item("ScopeParameter", "A parameter which represents the current scope.")]
   [StorableClass]
-  public class ScopeParameter : Parameter {
+  public class ScopeParameter : LookupParameter<IScope> {
     public new IScope ActualValue {
       get { return ExecutionContext.Scope; }
     }
+
 
     [StorableConstructor]
@@ -40,13 +42,13 @@
     protected ScopeParameter(ScopeParameter original, Cloner cloner) : base(original, cloner) { }
     public ScopeParameter()
-      : base("Anonymous", typeof(IScope)) {
+      : base("Anonymous") {
       this.Hidden = true;
     }
     public ScopeParameter(string name)
-      : base(name, typeof(IScope)) {
+      : base(name) {
       this.Hidden = true;
     }
     public ScopeParameter(string name, string description)
-      : base(name, description, typeof(IScope)) {
+      : base(name, description) {
       this.Hidden = true;
     }
