/// <summary> /// React on the event that a view has been closed /// </summary> /// <param name="sender">The view that has been closed.</param> /// <param name="e">The event's arguments.</param> public void OnViewClosed(IView sender, EventArgs e) { try { if (sender != null && this.viewCollection.Contains(sender)) { // the view belongs to this document! this.viewCollection.Remove(sender); this.viewControllerList.Remove(sender.ViewController); if (this.viewCollection.Count == 0) { // the last view has been closed // let this document and all associated data vanish sender.Close(); System.Diagnostics.Debug.Assert(this.viewControllerList.Count == 0, "No Views in the List"); this.viewCollection = null; this.viewControllerList = null; AppContext.DocumentList.Remove(this); AppContext.ViewClosed -= this.OnViewClosed; this.docContent = null; this.docObjects = null; this.selectedObjects = null; this.docName = string.Empty; this.fileName = string.Empty; GC.Collect(); // this a justifiable use of GC.Collect() since the last view of an document is closed and rather big amounts of data being freed. } } } catch (Exception ex) { Util.ReportException(ex); } }
/// <summary> /// Initializes a new instance of the <see cref="Document"/> class /// </summary> /// <remarks> /// Creates a new document. /// </remarks> public Document() { this.docObjects = new BaseObjectList(); this.viewCollection = new ViewCollection(); this.viewControllerList = new ViewControllerList(); this.selectedObjects = new BaseObjectList(); this.docName = string.Empty; this.fileName = string.Empty; this.docGuid = Guid.NewGuid(); AppContext.ViewClosed += this.OnViewClosed; }