Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/13 10:26:25 (12 years ago)
Author:
ascheibe
Message:

#2005

  • fixed naming of event handlers that were forgotten when the naming from experiment to job was changed
  • fixed some more memory leaks
Location:
branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r9170 r9173  
    4646
    4747    #region Properties
    48     private ItemCollection<RefreshableJob> jobs;
    49     public ItemCollection<RefreshableJob> Jobs {
     48    private HiveItemCollection<RefreshableJob> jobs;
     49    public HiveItemCollection<RefreshableJob> Jobs {
    5050      get { return jobs; }
    5151      set {
     
    8787
    8888    public void ClearHiveClient() {
     89      Jobs.ClearWithoutHiveDeletion();
    8990      foreach (var j in Jobs) {
    9091        if (j.RefreshAutomatically) {
    9192          j.RefreshAutomatically = false; // stop result polling
    92           j.Dispose();
    93         }
     93        }
     94        j.Dispose();
    9495      }
    9596      Jobs = null;
     97
    9698      if (onlinePlugins != null)
    9799        onlinePlugins.Clear();
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs

    r8939 r9173  
    3636  [Item("Hive Task", "Represents a hive task.")]
    3737  [StorableClass]
    38   public class HiveTask : NamedItem, IItemTree<HiveTask> {
     38  public class HiveTask : NamedItem, IItemTree<HiveTask>, IDisposable {
    3939    protected static object locker = new object();
    4040    protected ReaderWriterLockSlim childHiveTasksLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
     
    6767      set {
    6868        if (task != value) {
    69           DeregisterJobEvents();
     69          DeregisterTaskEvents();
    7070          task = value;
    71           RegisterJobEvents();
     71          RegisterTaskEvents();
    7272          IsFinishedTaskDownloaded = false;
    7373          OnTaskChanged();
     
    9393          itemTaskLock.EnterWriteLock();
    9494          try {
    95             DergisterItemTaskEvents();
     95            DeregisterItemTaskEvents();
    9696            itemTask = value;
    9797            RegisterItemTaskEvents();
     
    177177      this.childHiveTasks = new ItemList<HiveTask>();
    178178      syncTasksWithOptimizers = true;
    179       RegisterChildHiveJobEvents();
     179      RegisterChildHiveTasksEvents();
    180180    }
    181181
     
    198198      this.childHiveTasks = new ItemList<HiveTask>();
    199199      this.syncTasksWithOptimizers = true;
    200       RegisterChildHiveJobEvents();
     200      RegisterChildHiveTasksEvents();
    201201    }
    202202
     
    226226      }
    227227    }
    228     protected virtual void DergisterItemTaskEvents() {
     228    protected virtual void DeregisterItemTaskEvents() {
    229229      if (ItemTask != null) {
    230230        ItemTask.ComputeInParallelChanged -= new EventHandler(ItemJob_ComputeInParallelChanged);
     
    233233    }
    234234
    235     protected virtual void RegisterChildHiveJobEvents() {
     235    protected virtual void RegisterChildHiveTasksEvents() {
    236236      this.childHiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsAdded);
    237237      this.childHiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsRemoved);
    238238      this.childHiveTasks.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnCollectionReset);
    239239    }
    240     protected virtual void DeregisterChildHiveJobEvents() {
     240    protected virtual void DeregisterChildHiveTasksEvents() {
    241241      this.childHiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsAdded);
    242242      this.childHiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsRemoved);
     
    342342    }
    343343
    344     private void RegisterJobEvents() {
     344    private void RegisterTaskEvents() {
    345345      if (task != null)
    346346        task.PropertyChanged += new PropertyChangedEventHandler(task_PropertyChanged);
    347347    }
    348348
    349     private void DeregisterJobEvents() {
     349    private void DeregisterTaskEvents() {
    350350      if (task != null)
    351351        task.PropertyChanged += new PropertyChangedEventHandler(task_PropertyChanged);
     
    526526      this.ItemTask.Item = null;
    527527    }
     528
     529    public void Dispose() {
     530      DeregisterChildHiveTasksEvents();
     531      DeregisterTaskEvents();
     532      DeregisterItemTaskEvents();
     533      childHiveTasksLock.Dispose();
     534      itemTaskLock.Dispose();
     535    }
    528536  }
    529537
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/HiveTasks/OptimizerHiveTask.cs

    r8939 r9173  
    107107      }
    108108    }
    109     protected override void DergisterItemTaskEvents() {
    110       base.DergisterItemTaskEvents();
     109    protected override void DeregisterItemTaskEvents() {
     110      base.DeregisterItemTaskEvents();
    111111      if (ItemTask != null) {
    112112        if (ItemTask.Item is Optimization.Experiment) {
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs

    r9169 r9173  
    562562
    563563    public Guid Id {
    564       get { return job.Id; }
     564      get {
     565        if (job == null) return Guid.Empty;
     566        return job.Id;
     567      }
    565568      set { job.Id = value; }
    566569    }
     
    614617        jobDownloader = null;
    615618      }
     619      if (jobResultPoller != null) {
     620        DeregisterResultPollingEvents();
     621        jobResultPoller = null;
     622      }
     623      if (hiveTasks != null) {
     624        DisposeTasks();
     625      }
    616626      if (job != null) {
    617627        DeregisterJobEvents();
    618628        job = null;
    619629      }
    620       if (hiveTasks != null) {
    621         DeregisterHiveTasksEvents();
    622         hiveTasks.Clear(); // this should remove the item_StateLogChanged event handlers
    623         hiveTasks = null;
    624       }
    625       if (jobResultPoller != null) {
    626         DeregisterResultPollingEvents();
    627         jobResultPoller = null;
    628       }
     630    }
     631
     632    private void DisposeTasks() {
     633      DeregisterHiveTasksEvents();
     634      foreach (var task in hiveTasks) {
     635        task.Dispose();
     636      }
     637      hiveTasks.Clear(); // this should remove the item_StateLogChanged event handlers
     638      hiveTasks = null;
    629639    }
    630640    #endregion
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveItemCollection.cs

    r7259 r9173  
    5252    }
    5353
     54    public void ClearWithoutHiveDeletion() {
     55      if (list.Count > 0) {
     56        T[] items = list.ToArray();
     57        list.Clear();
     58        OnPropertyChanged("Count");
     59        //don't call OnCollectionReset directly as it would delete the job
     60        base.OnCollectionReset(list, items);
     61      }
     62    }
     63
    5464    private void RemoveItems(IEnumerable<T> items, out IEnumerable<T> successful, out IEnumerable<T> unsuccessful, out Exception exception) {
    5565      List<T> removed = new List<T>();
Note: See TracChangeset for help on using the changeset viewer.