Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
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 
No, what I'm saying is this -

private void DoSomething()
{
(new Form2()).Show();
}
When Form2 is Closed (user action) Dispose(true) is automatically called by the CLR.

All fine. But after calls to GC.Collect() or GC.GetTotalMemory(true) (both of which should force GC) the form (plus all the controls for the form are never GC'd)

However,

private void DoSomething()
{
(new Form2()).ShowDialog();
}

When Form2 is Closed (user action) Dispose(true) is NOT automatically called by the CLR and shortly after, typically when further memory allocations are required the form gets CG'd.

My point is then that (new Form2()).Show(); requires that a reference to the form be promoted somewhere within the CLR (or O/S) to keep track of the form as the DoSomething() method completes immediately. The internal reference to the form is never removed, even when the form is closed (only when the app terminates) so the form (and all of the form's controls) can never be GC'd.

The typical base managed heap allocation for a complex form instance (multiple pages, multiple controls) appears to be around 1 to 2 megabytes (not including data) which remains after the form is Disposed. The application (an Mdi ERP solution) has around 500 forms and has a user base of around 150 users within the client organisation. The client decision to distribute the solution through Citrix is directly impacted by the cumulative effect of additional memory usage over 20 to 30 users on a typical Citrix server box.

So if no way can be found to force the CLR (or O/S) to relinquish the reference to the form after it is closed and therefore eventually be GC'd then the client decision to distribute the solution through Citrix will need to be seriously re-evaluated.

(Not the case for ShowDialog() which does not terminate the DoSomething() method until the form is Closed()) (therefore no promotion is necessary)





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 
QuestionMVC custom control Pin
alex.barylski28-Apr-07 20:22
alex.barylski28-Apr-07 20:22 
AnswerRe: MVC custom control Pin
Christian Graus28-Apr-07 21:38
protectorChristian Graus28-Apr-07 21:38 
GeneralRe: MVC custom control Pin
alex.barylski29-Apr-07 7:41
alex.barylski29-Apr-07 7:41 
GeneralRe: MVC custom control Pin
Christian Graus29-Apr-07 11:02
protectorChristian Graus29-Apr-07 11:02 
Questionoverlaying image on a video file Pin
enamulhoque28-Apr-07 19:27
enamulhoque28-Apr-07 19:27 
AnswerRe: overlaying image on a video file Pin
Christian Graus28-Apr-07 21:39
protectorChristian Graus28-Apr-07 21:39 
GeneralRe: overlaying image on a video file Pin
enamulhoque29-Apr-07 4:27
enamulhoque29-Apr-07 4:27 
GeneralRe: overlaying image on a video file Pin
Christian Graus29-Apr-07 10:51
protectorChristian Graus29-Apr-07 10:51 
QuestionUnsafe code Pin
xibeifeijian28-Apr-07 15:54
xibeifeijian28-Apr-07 15:54 
AnswerRe: Unsafe code Pin
Christian Graus28-Apr-07 16:50
protectorChristian Graus28-Apr-07 16:50 
GeneralRe: Unsafe code Pin
xibeifeijian28-Apr-07 17:12
xibeifeijian28-Apr-07 17:12 
GeneralRe: Unsafe code Pin
Arun.Immanuel28-Apr-07 17:14
Arun.Immanuel28-Apr-07 17:14 
GeneralRe: Unsafe code Pin
Christian Graus28-Apr-07 17:44
protectorChristian Graus28-Apr-07 17:44 
GeneralRe: Unsafe code Pin
Arun.Immanuel28-Apr-07 17:48
Arun.Immanuel28-Apr-07 17:48 

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.