User objects not Removed

Topics: CAB & Smart Client Software Factory
Aug 30, 2006 at 3:42 AM
originally posted by: ForumUserRCC

I expected that if a View contained other used controls, that by removing the view, any user control would also be removed. But that isn't happening. The user controls are added into the View via the designer of VS2005, so they are getting instantiated when the View does. Since that is the container for the controls, Disposing it I would think would also dispose of any user controls it containes.

I have a view (View1) that has in it View2 which is a user control. Both views created via the SCSF. (Had to use a work around in order to be able to place one user control into another since they don't appear in the Toolbox as expected due to a VS2005 problem with Solution folders.)

It comes to a point where I need to close and remove View1. I then later need to present View1 again(different set of data). When it tries to "Show" the view, i get an error that the View2 control already exists. I would have thought that by getting, removing, and disposing View1 (which contains View2) that View2 would have also gone away.

If I explicitly so the same get, remove, dispose on the View2 user ocntrol, then the code works. So there is a way around it.
I expected though that since its "container" was disposed, then the control itself also should have been disposed without having to do it explicitly.