Click here to Skip to main content
15,896,479 members
Home / Discussions / C#
   

C#

 
AnswerRe: Network IPs Pin
Arun.Immanuel29-Apr-07 5:12
Arun.Immanuel29-Apr-07 5:12 
QuestionForcing a class to be shared over webservice Pin
lütfen29-Apr-07 1:08
lütfen29-Apr-07 1:08 
AnswerRe: Forcing a class to be shared over webservice Pin
Arun.Immanuel29-Apr-07 1:57
Arun.Immanuel29-Apr-07 1:57 
GeneralRe: Forcing a class to be shared over webservice Pin
lütfen29-Apr-07 2:16
lütfen29-Apr-07 2:16 
Questionhow to hide a panel on child form, when child form loads? Pin
Saira Tanwir29-Apr-07 1:04
Saira Tanwir29-Apr-07 1:04 
AnswerRe: how to hide a panel on child form, when child form loads? Pin
Arun.Immanuel29-Apr-07 1:46
Arun.Immanuel29-Apr-07 1:46 
QuestionBandwidth Utilization Pin
jkjadoon28-Apr-07 23:15
jkjadoon28-Apr-07 23:15 
QuestionGarbage Collection & Memory Leaks. Pin
coleydog28-Apr-07 22:45
coleydog28-Apr-07 22:45 
Hi all,

For the last several days I've been trying to figure out why my windows mdi forms application doesn't tidy up resources correctly and continues to grow through multiple iterations of the same processes - ie Leaks Memory. To that end I created a small (single form) test Windows Application (TestGC). The TestGC form has 3 buttons (buttonShow, buttonShowDialog, buttonCollect) and a text box (textBoxMemory). The TestGC app was created as a standard vanilla app using VS (VS2005).

I added the following line to the form Dispose method

System.Diagnostics.Debug.WriteLine( "disp-"
+ HashIdent() + disposing.ToString() );

and the following code to the TestGC form class.

public readonly string testGCSource;

public TestGC( string testGCSource ) : this() {
this.testGCSource = testGCSource;
this.Text = HashIdent();
System.Diagnostics.Debug.WriteLine( "ctor." + HashIdent() );
}

public TestGC() {
this.testGCSource = String.Empty;
InitializeComponent();
}

private string HashIdent() {
return String.Format( "TestGC:{0}[{1}]",
this.testGCSource, this.GetHashCode() );
}

private void buttonShow_Click( object sender, EventArgs e ) {
(new TestGC( "Show" )).Show();
}

private void buttonShowDialog_Click( object sender, EventArgs e ) {
(new TestGC( "ShowDialog" )).ShowDialog( this );
}

private void buttonCollect_Click( object sender, EventArgs e ) {
this.textBoxMemory.Text = System.GC.GetTotalMemory( true ).ToString("N0");
}

~TestGC() {
System.Diagnostics.Debug.WriteLine( "dtor~" + HashIdent() );
}

What the simple test app demonstrates is that a form and all of its controls when displayed using the Show() method are NEVER destructed, they are Disposed(true) but not ever destructed. That is the class instance once created is never destroyed. This seems to be a total disaster (obviously not here, but for complex, multi-paged forms with perhaps hundreds of controls in mdi projects with many hundreds of forms) and is by every definition an example of a true memory leak. (The ShowDialog display method on form Close does call the destructor and gets fully GC'ed).


So my questions -

Is there any way to request of the GC why it will not specifically Finalize a class instance?

Is there any way to force the GC to Finalize (destruct) a Windows component? (Form + Controls).
(ie Is there a WinApi type dll call to force the Form (+ Controls) to go out of scope and be GC'ed?

From the above code it is obvious there are no 'local' references to any component after the Dispose method is called.

Thanks in advance,

David.



AnswerRe: Garbage Collection & Memory Leaks. Pin
lmoelleb28-Apr-07 22:56
lmoelleb28-Apr-07 22:56 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 5:18
coleydog29-Apr-07 5:18 
GeneralRe: Garbage Collection & Memory Leaks. Pin
lmoelleb29-Apr-07 7:03
lmoelleb29-Apr-07 7:03 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 20:03
coleydog29-Apr-07 20:03 
GeneralRe: Garbage Collection & Memory Leaks. Pin
lmoelleb29-Apr-07 21:26
lmoelleb29-Apr-07 21:26 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 22:40
coleydog29-Apr-07 22:40 
AnswerRe: Garbage Collection & Memory Leaks. Pin
Christian Graus29-Apr-07 0:14
protectorChristian Graus29-Apr-07 0:14 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 5:25
coleydog29-Apr-07 5:25 
GeneralRe: Garbage Collection & Memory Leaks. Pin
Christian Graus29-Apr-07 10:52
protectorChristian Graus29-Apr-07 10:52 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 16:36
coleydog29-Apr-07 16:36 
GeneralRe: Garbage Collection & Memory Leaks. Pin
Christian Graus29-Apr-07 18:15
protectorChristian Graus29-Apr-07 18:15 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 22:56
coleydog29-Apr-07 22:56 
GeneralRe: Garbage Collection & Memory Leaks. Pin
caix29-Apr-07 14:11
caix29-Apr-07 14:11 
GeneralRe: Garbage Collection & Memory Leaks. Pin
coleydog29-Apr-07 16:19
coleydog29-Apr-07 16:19 
GeneralRe: Garbage Collection & Memory Leaks. Pin
Dave Kreskowiak29-Apr-07 16:55
mveDave Kreskowiak29-Apr-07 16:55 
QuestionHow to get Status of Process (Urgent) Pin
Sanjib Raj28-Apr-07 22:18
Sanjib Raj28-Apr-07 22:18 
AnswerRe: How to get Status of Process (Urgent) Pin
Amir Jalaly29-Apr-07 1:51
Amir Jalaly29-Apr-07 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.