Changeset 9173


Ignore:
Timestamp:
01/18/13 10:26:25 (8 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
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/UnloadJobs/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveJobManagerView.cs

    r9169 r9173  
    5555      Content.Refreshed += new EventHandler(Content_Refreshed);
    5656      Content.HiveJobsChanged += new EventHandler(Content_HiveJobsChanged);
    57 
    5857    }
    5958
     
    131130          Content.Jobs.ItemsRemoved -= new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved);
    132131          Content.ClearHiveClient();
     132          Content = null;
    133133        }
    134134      }
     
    143143    private void Content_HiveJobsChanged(object sender, EventArgs e) {
    144144      if (Content.Jobs != null) {
     145        Content.Jobs.ItemsRemoved -= new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved);
    145146        Content.Jobs.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved);
    146147      }
  • branches/UnloadJobs/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r9107 r9173  
    100100        progressView = null;
    101101      }
     102      DeregisterHiveExperimentEvents();
     103      DeregisterHiveTasksEvents();
    102104      base.DeregisterContentEvents();
    103105    }
     
    111113    }
    112114
    113     private void RegisterHiveJobEvents() {
     115    private void RegisterHiveTasksEvents() {
    114116      Content.HiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
    115117      Content.HiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
    116118      Content.HiveTasks.CollectionReset += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset);
    117119    }
    118     private void DeregisterHiveJobEvents() {
     120    private void DeregisterHiveTasksEvents() {
    119121      Content.HiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
    120122      Content.HiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
     
    131133          resourceNamesTextBox.Text = string.Empty;
    132134          isPrivilegedCheckBox.Checked = false;
    133           logView.Content = null;
    134135          refreshAutomaticallyCheckBox.Checked = false;
    135136          lock (runCollectionViewLocker) {
    136137            runCollectionViewHost.Content = null;
    137138          }
     139          logView.Content = null;
     140          jobsTreeView.Content = null;
     141          hiveExperimentPermissionListView.Content = null;
     142          stateLogViewHost.Content = null;
    138143        } else {
    139144          nameTextBox.Text = Content.Job.Name;
     
    286291        if (Content != null && Content.HiveTasks != null) {
    287292          jobsTreeView.Content = Content.HiveTasks;
    288           RegisterHiveJobEvents();
     293          RegisterHiveTasksEvents();
    289294        } else {
    290295          jobsTreeView.Content = null;
     
    435440
    436441    private void nameTextBox_Validated(object sender, EventArgs e) {
    437       if (!SuppressEvents && Content.Job.Name != nameTextBox.Text)
     442      if (!SuppressEvents && Content.Job != null && Content.Job.Name != nameTextBox.Text)
    438443        Content.Job.Name = nameTextBox.Text;
    439444    }
    440445
    441446    private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
    442       if (!SuppressEvents && Content.Job.ResourceNames != resourceNamesTextBox.Text)
     447      if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)
    443448        Content.Job.ResourceNames = resourceNamesTextBox.Text;
    444449    }
  • branches/UnloadJobs/HeuristicLab.Clients.Hive.Views/3.3/TreeView/HiveTaskItemTreeView.cs

    r8120 r9173  
    3535      get { return (ItemCollection<HiveTask>)base.Content; }
    3636      set { base.Content = value; }
     37    }
     38
     39    protected override void OnContentChanged() {
     40      if (Content == null) {
     41        foreach (var t in Content) {
     42          t.Dispose();
     43        }
     44      }
     45      base.OnContentChanged();
    3746    }
    3847
  • 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.