Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 201823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:13:59+00:00 2026-05-11T17:13:59+00:00

I did nice winforms 2.0 application and it’s working great and customers are still

  • 0

I did nice winforms 2.0 application and it’s working great and customers are still happy but unfortunatelly I cannot solve one issue. The problem is that after using app for a couple of hours, gdi user handles number is rising and rising and finally process cannot allocate more objects and app crashes…

I’m not doing anything fancy, it’s regular app, a few forms, a few more modal forms, a few datagridviews and a lot tablelayoutpanels where I’m adding a lot labels and textboxes.

My questions are:

  • are there any “recommended-practises”
    concerning adding/removing regular system
    controls on forms at runtime (dgv/tlp)
  • how to detect system handles’
    leaks – preferably using visual
    studio and a kind of free plugin
    (profiler?)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:13:59+00:00Added an answer on May 11, 2026 at 5:13 pm

    Detecting graphics and window handle leaks is very difficult. As to a particular strategy for finding them at runtime, I can’t suggest anything (though I’d love to hear someone else’s!).

    As for preventing them, here are a couple of reminders:

    • While the Control class’s finalizer will call Dispose(), this is non-deterministic. You are not guaranteed that ANY object will EVER get finalized by the garbage collector. It’s likely that it will, but it’s not a guarantee.
    • In keeping with the above, Forms are an exception. When a Form is shown in a NON-MODAL way (meaning through Show(), NOT ShowDialog()), then when the Form closes it will deterministically call Dispose(). Forms that are shown through ShowDialog() must have Dispose() called manually in order to deterministically clean up the control handle.
    • Keeping those two things in mind, the most important thing that you can do is to ensure that you always call Dispose() on any object that you explicitly create that implements IDisposable. This INCLUDES Forms, Controls, Graphics objects, even the graphics helper classes like Pen and Brush. All of those classes implement IDisposable, and all of them need to be disposed of as soon as you no longer need them.
    • Try to cache your graphics utility classes, assuming you’re using some. While a Pen and a Brush are fairly lightweight to create, they do take up handles and need to be disposed of when you’re finished. Rather than creating them all the time, create a cache manager that allows you to pass in the parameters that you would use in the constructor for those objects and keep that object around. Repeated calls with the same parameters should still only use one single instance. You can then flush your cache on a periodic basis or at specific places in your application if you know where those would be.

    Following those guidelines will greatly reduce–if not eliminate–your handle leaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did my first application of mailer php today, very nice, sending 2 pdf
I did mockups in balsamiq & they have this nice widget, which Allowed to
Did someone create a nice stylesheet for this: http://mvccontrib.codeplex.com/wikipage?title=Grid&referringTitle=Documentation&ProjectName=mvccontrib Thanks. Christian
did you know a php script (a class will be nice) who get the
Trying to convert super(B, self).method() into a simple nice bubble() call. Did it ,
Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way
I don't know what I did but for a period of time my TabWidget
I did some searching but haven't landed anything that looks useful yet but I
Did ask a question about the same problem here: Silly problem with UTF8 but
I did some numbers and ended up finding that on my application, if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.