Index: /trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj	(revision 6102)
+++ /trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj	(revision 6103)
@@ -121,4 +121,5 @@
     <Compile Include="Content\IStorableContent.cs" />
     <Compile Include="Constants.cs" />
+    <Compile Include="ObjectExtensions.cs" />
     <Compile Include="DeepCloneable.cs" />
     <Compile Include="Content\IContent.cs" />
Index: /trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs
===================================================================
--- /trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs	(revision 6103)
+++ /trunk/sources/HeuristicLab.Common/3.3/ObjectExtensions.cs	(revision 6103)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace HeuristicLab.Common {
+  public static class ObjectExtensions {
+    public static IEnumerable<object> GetObjectGraphObjects(this object obj) {
+      var objects = new HashSet<object>();
+      obj.CollectObjectGraphObjects(objects);
+      return objects;
+    }
+
+    private static void CollectObjectGraphObjects(this object obj, HashSet<object> objects) {
+      if (obj == null || obj is EventHandler || obj.GetType().IsSubclassOfRawGeneric(typeof(EventHandler<>)) || objects.Contains(obj)) return;
+      objects.Add(obj);
+
+      if (obj is ValueType || obj is string) return;
+
+      IEnumerable enumerable = obj as IEnumerable;
+      if (enumerable != null) {
+        foreach (object value in enumerable) {
+          value.CollectObjectGraphObjects(objects);
+        }
+      } else {
+        foreach (FieldInfo f in obj.GetType().GetAllFields()) {
+          f.GetValue(obj).CollectObjectGraphObjects(objects);
+        }
+      }
+    }
+  }
+}
Index: /trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs
===================================================================
--- /trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs	(revision 6102)
+++ /trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs	(revision 6103)
@@ -21,4 +21,6 @@
 
 using System;
+using System.Collections.Generic;
+using System.Reflection;
 using System.Text;
 
@@ -45,4 +47,29 @@
       return sb.ToString();
     }
+    public static IEnumerable<FieldInfo> GetAllFields(this Type type) {
+      foreach(var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) 
+        yield return field;
+
+      foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 
+        yield return field;
+      
+      if (type.BaseType != null) {
+        foreach (var field in type.BaseType.GetAllFields())
+          yield return field;
+      }
+    }
+    // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class
+    public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) {
+      while (toCheck != typeof(object)) {
+        var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
+        if (generic == cur) {
+          return true;
+        }
+        toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface
+        if (toCheck == null)
+          return false;
+      }
+      return false;
+    }
   }
 }
Index: /trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj	(revision 6102)
+++ /trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj	(revision 6103)
@@ -147,4 +147,5 @@
     <Compile Include="Interfaces\IMultiOperator.cs" />
     <Compile Include="Interfaces\IFixedValueParameter.cs" />
+    <Compile Include="Interfaces\IStatefulItem.cs" />
     <Compile Include="OperatorExecutionException.cs" />
     <Compile Include="Interfaces\IScopeTreeLookupParameter.cs" />
Index: /trunk/sources/HeuristicLab.Core/3.3/Interfaces/IStatefulItem.cs
===================================================================
--- /trunk/sources/HeuristicLab.Core/3.3/Interfaces/IStatefulItem.cs	(revision 6103)
+++ /trunk/sources/HeuristicLab.Core/3.3/Interfaces/IStatefulItem.cs	(revision 6103)
@@ -0,0 +1,27 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+namespace HeuristicLab.Core {
+  public interface IStatefulItem : IItem {
+    void InitializeState();
+    void ClearState();
+  }
+}
Index: /trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
===================================================================
--- /trunk/sources/HeuristicLab.Operators/3.3/Operator.cs	(revision 6102)
+++ /trunk/sources/HeuristicLab.Operators/3.3/Operator.cs	(revision 6103)
@@ -33,5 +33,5 @@
   [Item("Operator", "Base class for operators.")]
   [StorableClass]
-  public abstract class Operator : ParameterizedNamedItem, IOperator {
+  public abstract class Operator : ParameterizedNamedItem, IOperator, IStatefulItem {
     public override Image ItemImage {
       get {
@@ -74,35 +74,42 @@
     protected Operator(bool deserializing)
       : base(deserializing) {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
     }
     protected Operator(Operator original, Cloner cloner)
       : base(original, cloner) {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
       this.breakpoint = original.breakpoint;
     }
     protected Operator()
       : base() {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
       breakpoint = false;
     }
     protected Operator(string name)
       : base(name) {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
       breakpoint = false;
     }
     protected Operator(string name, ParameterCollection parameters)
       : base(name, parameters) {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
       breakpoint = false;
     }
     protected Operator(string name, string description)
       : base(name, description) {
-      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      InitializeState();
       breakpoint = false;
     }
     protected Operator(string name, string description, ParameterCollection parameters)
       : base(name, description, parameters) {
+      InitializeState();
+      breakpoint = false;
+    }
+
+    public virtual void InitializeState() {
       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
-      breakpoint = false;
+    }
+    public virtual void ClearState() {
+      executionContexts = null;
     }
 
Index: /trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs	(revision 6102)
+++ /trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs	(revision 6103)
@@ -261,4 +261,7 @@
     protected virtual void OnPrepared() {
       ExecutionTime = TimeSpan.Zero;
+      foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) {
+        statefulObject.InitializeState();
+      }
       ExecutionState = ExecutionState.Prepared;
       EventHandler handler = Prepared;
@@ -280,4 +283,7 @@
     protected virtual void OnStopped() {
       ExecutionState = ExecutionState.Stopped;
+      foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) {
+        statefulObject.ClearState();
+      }
       runsCounter++;
       runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
Index: /trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
===================================================================
--- /trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs	(revision 6102)
+++ /trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs	(revision 6103)
@@ -33,5 +33,5 @@
   [Item("Parameter", "A base class for parameters.")]
   [StorableClass]
-  public abstract class Parameter : NamedItem, IParameter {
+  public abstract class Parameter : NamedItem, IParameter, IStatefulItem {
     public override Image ItemImage {
       get {
@@ -92,6 +92,5 @@
     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);
+      InitializeState();
     }
     protected Parameter(Parameter original, Cloner cloner)
@@ -99,6 +98,5 @@
       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);
+      InitializeState();
     }
     protected Parameter()
@@ -106,6 +104,5 @@
       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);
+      InitializeState();
     }
     protected Parameter(string name, Type dataType)
@@ -114,6 +111,5 @@
       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);
+      InitializeState();
     }
     protected Parameter(string name, string description, Type dataType)
@@ -122,6 +118,14 @@
       this.dataType = dataType;
       hidden = false;
+      InitializeState();
+    }
+
+    public virtual void InitializeState() {
       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 ClearState() {
+      cachedActualValues = null;
+      executionContexts = null;
     }
 
