Flicker and dispose

G

Guest

Hi all

Got a problem with my application. Whenever I close a form that's been shown through ShowDialog() and go back to the parent form, whatever is running behind my app (Usually VS), appears very briefly - and creates a flickering effect

I've enabled double buffering on all my forms, and it has improved it somewhat, but it still occurs

The problem I think is that I am calling Dispose() on each form in the Closed event. This is because we've found that DotNet often doesn't garbage collect instances of forms if they aren't explicitly disposed, so we call
this.Dispose(true)
GC.SuppressFinalize(this)
in the Closed event. If we don't do this our app quickly starts chewing up memory and on low-end machines causes thrashing.

I tried not calling dispose on some forms and the flickering disappeared
So the question is, has anyone had this problem or does anyone have any ideas as to how to reduce the flickering and still allow the GC to collect the forms correctly

Thanks in advance
Simon
 
J

Justin Rogers

Option 1, re-use the forms that are being displayed through ShowDialog().

Suggestions if you can't do that are:
Make sure you Close() the child dialog
Call Dispose() from your parent form, not from the Child Form event
Remove the SuppressFinalize since this is called by default in the Dispose()
public method

Re-using the dialog form over and over again will save you a LOT of resources in
the long
term and is probably the best way to conserve memory on low end machines. The
cost here
is you'll need some way to put the forms into a *clean* state between calls.
Placing your
cleaning logic in VisibleChanged is good for this.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


SimonH said:
Hi all,

Got a problem with my application. Whenever I close a form that's been shown
through ShowDialog() and go back to the parent form, whatever is running behind
my app (Usually VS), appears very briefly - and creates a flickering effect.
I've enabled double buffering on all my forms, and it has improved it somewhat, but it still occurs.

The problem I think is that I am calling Dispose() on each form in the Closed
event. This is because we've found that DotNet often doesn't garbage collect
instances of forms if they aren't explicitly disposed, so we call:
this.Dispose(true);
GC.SuppressFinalize(this);
in the Closed event. If we don't do this our app quickly starts chewing up
memory and on low-end machines causes thrashing.
I tried not calling dispose on some forms and the flickering disappeared.
So the question is, has anyone had this problem or does anyone have any ideas
as to how to reduce the flickering and still allow the GC to collect the forms
correctly?
 
G

Guest

Hi Justin

Took option 2, now calling dispose from the parent form and it works like a charm

Thanks for your help

Simon
 
S

Stu Smith

Set the form's DialogResult instead of calling close.

Stu

SimonH said:
Hi all,

Got a problem with my application. Whenever I close a form that's been
shown through ShowDialog() and go back to the parent form, whatever is
running behind my app (Usually VS), appears very briefly - and creates a
flickering effect.
I've enabled double buffering on all my forms, and it has improved it somewhat, but it still occurs.

The problem I think is that I am calling Dispose() on each form in the
Closed event. This is because we've found that DotNet often doesn't garbage
collect instances of forms if they aren't explicitly disposed, so we call:
this.Dispose(true);
GC.SuppressFinalize(this);
in the Closed event. If we don't do this our app quickly starts chewing up
memory and on low-end machines causes thrashing.
I tried not calling dispose on some forms and the flickering disappeared.
So the question is, has anyone had this problem or does anyone have any
ideas as to how to reduce the flickering and still allow the GC to collect
the forms correctly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top