Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/17/10 07:41:28 (14 years ago)
Author:
swagner
Message:

Fixed memory leak when using parameters whose values are not deeply cloned (#1268)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Run.cs

    r4722 r4825  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Linq;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    8788
    8889    private void Initialize(IAlgorithm algorithm) {
    89       IAlgorithm clone = (IAlgorithm)algorithm.Clone();
    9090      parameters = new Dictionary<string, IItem>();
    9191      results = new Dictionary<string, IItem>();
    92       clone.CollectParameterValues(parameters);
    93       clone.CollectResultValues(results);
    94       if (clone.StoreAlgorithmInEachRun) {
     92
     93      if (algorithm.StoreAlgorithmInEachRun) {
     94        IAlgorithm clone = (IAlgorithm)algorithm.Clone();
     95        clone.CollectParameterValues(parameters);
     96        clone.CollectResultValues(results);
    9597        clone.Prepare(true);
    9698        this.algorithm = clone;
     99      } else {
     100        algorithm.CollectParameterValues(parameters);
     101        algorithm.CollectResultValues(results);
     102        Cloner cloner = new Cloner();
     103        parameters = parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, (IItem)x.Value.Clone(cloner))).ToDictionary(x => x.Key, x => x.Value);
     104        results = results.Select(x => new KeyValuePair<string, IItem>(x.Key, (IItem)x.Value.Clone(cloner))).ToDictionary(x => x.Key, x => x.Value);
    97105      }
    98106    }
Note: See TracChangeset for help on using the changeset viewer.