controls - detecting gdi / user handler leaks in winforms -


I have applied good configuration 2.0 and it is working very well and the customer is still happy but unfortunately I Can not solve the issue. The problem is that after using the app for a few hours, the GDI user handles the number increases and increases and finally the process can not allocate more objects and app crashes ...

I'm not fancy anything, this regular app, some forms, some modal forms, some datagrid views and many tablelay panels, where I am adding a lot of labels and text boxes.

My questions are:

  • Are there any "recommended practices" about adding / removing regular system controls on forms on runtime (DGV / TLP)?
  • How does the system leak to detect - preferably using Visual Studio and a kind of free plugin (profiler?)

< Div class = "post-text" itemprop = "text">

Graphics and window handle leaks are very difficult to detect, as a special strategy to find them at runtime, I can not suggest anything (though I would love to hear something else!).

To prevent them, here are some reminders: / P>

  • While control the last person in the class, Will call, it is non deterministic, you are not guaranteed that any object will be finalized by the garbage collector. This is likely to happen, but it is not a guarantee.
  • With the above, the form is an exception. When a form is shown in a non-model manner (which means show () , not ShowDialog () ), then when Forms stops, it will definitely call dissection () . The form shown through is shown should be called manually disposable () so that the control handle is clearly controlled.
  • Keeping these two things in mind, the most important thing is that you have to ensure that you always call disposed ( any object) Which you explicitly make IDisposable in the form s, control s, graphics objects, even That graphics assistant class like pen and brush . All those classes implement the IDisposable , and all of them should be dealt with as soon as they do not need them anymore.
  • Try caching your graphics utility classes, using something again while creating a pen and brushes They are handy, they take handles and when you are finished, they should be disposed of instead of making them all the time, create a cash manager who allows you to pass those standards which you have created in the Constructor for those objects Use the Gay and keep that object all around Repeated calls with the same parameter should still use only a single instance. Then you can flush your cash on periodic basis or in your specific places if you know where it will be.

Following these guidelines will be greatly reduced - if not more then - to handle your leaks.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -