CloseView does not delete View/Presenter

Topics: CAB & Smart Client Software Factory
Jul 14, 2006 at 11:45 AM
originally posted by: Mummas

I found that the CloseView does not delete the View or the presenter! Breakpoints in the dispose methods are not hit on CloseView. They are hit during when closing the app and the DeckWorkspace dispose is called.

What do we need to delete the View/Presenter objects?
Jul 18, 2006 at 9:24 AM
originally posted by: matiaswoloski

Hi Mummas,

CloseView will close the view from the workspace (wks.Close(view)).
Disposing the view depends on the context and we didn't want to generalize that. Maybe you want to close the view but you want to reuse that view in another workspace. That's why we decided to not dispose the view when it's closed.

However, if you choose to dispose the view you can write this in your presenter:

CloseView();
if (View is IDisposable) ((IDisposable) View).Dispose();

Regarding disposing the presenter. When you generate a view with the Guidance Package, the UserControl will have this code in the Dispose method:

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_presenter != null)
_presenter.Dispose();

if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}

So when the view is disposed, the presenter will be disposed.

Thanks
Matias
http://staff.southworks.net/blogs/matiaswoloski
Sep 13, 2006 at 10:37 AM
originally posted by: Mummas

Matias,
Thanks for the info. But the CloseView() only removed the View from the Workspace's smartParts list. I had to remove the view from the WorkItem's smartPartCollection list also to wipe out the View. So the final code is as follows:

WorkItem.SmartParts.Remove(View);
CloseView();
if (View is IDisposable) ((IDisposable)View).Dispose();