none
axHost not releasing GDI resources RRS feed

  • Question

  • I have a ActiveX Control that is being used inside of a .net 2.0 project.  The ActiveX Control is being created by using axtivex wrapper that uses  the AxHost class inside of the System.Windows.Forms dll.  The problem that I am having is that when I create the activeX Control and then dispose the Control, the control is removed from memory but the GDI count does not ever go down.  After creating/removing the control over and over eventually the gdi count gets to high and the application crashes or gives me an out of memory error.

    I found the following article that pertains to 1.1 that sounds like it had the same problem.  http://support.microsoft.com/kb/940737  However I am in 2.0 and was wondering if this was ever fixed in 2.0. 

    If this has been fixed in 2.0 can you think of any reason why it may still be a problem for me.

    Thanks
    Tuesday, May 26, 2009 7:21 PM

All replies

  • GDI objects are not reference counted, COM doesn't deal with them.  AxHost is completely agnostic too, all the painting is left to the control.  Leaking them in the painting code in unmanaged C/C++ is a classic bug.  Do make sure you call the AxHost.Dispose() method if you remove the control yourself instead of letting the Form's automatic cleanup code take care of it.  If you don't, you'd be leaking USER32 objects (window handles) and the ActiveX object instance.  Otherwise, contact the control vendor for support.

    Hans Passant.
    Wednesday, May 27, 2009 2:01 AM
    Moderator
  • The control doesn't leak any gdi objects when used in an unmanaged application, it only leaks them when used through the AxHost.   Good suggestion on the AxHost.Dispose method but I have already tried that with no success.  Any other suggestions?

    Thanks
    Wednesday, May 27, 2009 1:10 PM
  • Hi Keith,

    I am curious to know if you ever found a solution or answer for this that helped?

    We are having a similar issue in Visual Studio 2005 .Net 2.0

    Thanks.
    Thursday, August 20, 2009 8:41 PM