Smart Device designer does not add objects deriving from System.ComponentModel.Component to components collection - by Mike Dimmick

Status : 

 


15
0
Sign in
to vote
ID 305534 Comments
Status Active Workarounds
Type Bug Repros 4
Opened 10/18/2007 7:42:05 AM
Access Restriction Public

Description

Components dragged onto a form which implement System.ComponentModel.IComponent are placed in a 'components' collection (an instance of System.ComponentModel.Container) for desktop/server projects. This does not occur for smart device projects.

The generated Dispose(bool) override for a Form checks whether 'components' has been initialized and if so, calls Dispose on it. However, this field is never initialized by the generated code so it is always null.

The System.ComponentModel.Component class implements a finalizer in .NET Compact Framework 2.0. The Dispose() method calls GC.SuppressFinalize(this). The designer however does not generate calls to Dispose for objects derived from Component.

System.Windows.Forms.MainMenu derives from Component, as does MenuItem. Objects of these classes are not disposed of when the owning form is disposed because of this issue. Nor are event handlers detached.

The result of this is that components are unnecessarily staying on the finalization queue and potentially a large object graph is retained after a garbage collection, due to any event handlers remaining connected to the form object. This leads to excessive memory use.

The designer should ensure that all non-graphical components dragged onto a form are disposed of when the form is disposed, to ensure that finalizers are not invoked unnecessarily.
Sign in to post a comment.
Posted by Mike Dimmick on 12/4/2007 at 5:30 PM
This bug is still present in the final RTM release of Visual Studio 2008.
Posted by Mike Dimmick on 10/22/2007 at 1:54 AM
This problem appears to also be present in Visual Studio 2008 Beta 2.