So I played around with Task Manager adding Handles, User OBject, and GDI
Objects to the columns collection and lo-and-behold, when User Objects
reached 10000, BOOM! The program crashed. So, I looked into my code, wrote
some cleanup code, handled the destruction of objects in the dispose method
myself and wham ... User Objects never gets above 175, and it no longer
crashes.
Stupid me, I was re-creating the user control, but not disposing of the
previous labels and panels.
So, for all you folks who have had trouble with Window Handles, it may not
be the window handles, but the User Objects counter that's important. If you
keep creating objects on a form without destroying the previous one due to
some input or from the user or something else... you'll probably having the
same problem.
-Joel
> I have an application that does the following in one of its user controls:
>
[quoted text clipped - 18 lines]
>
> Thx, Joel
Jeffrey Tan - 12 Sep 2004 14:29 GMT
Hi Joel,
I am very glad your problem resolved :-).
In .Net, there are 2 types of resource freeing: managed objects and
unmanaged resources. All .Net class instances are managed resource, CLR will
add reference counters on these objects, once one instance's reference count
drops to 0, it will be implicitly collected by GC. For unmanaged resources,
they are not .Net's type, but the resource of Windows, such as windows
handle, database connections, bitmap memory, etc. .Net will not manage
resource counter for them, .Net use IntPtr pointer to marshal them, .Net has
nothing knowledge of them and we should handle the resource free of them
ourselves. Implicitly, GC will invoke finalize method before collect the
managed resource, finalize method will free the unmanged sources. But when
unmanaged resource is rarity, such as the memory is not large for bitmap, or
our application uses too much Win32 resouces, there should be a way to
explicitly free the unmanaged resource, this explicit way is Dispose method.
A USER object is an object from Window Manager, which includes windows,
menus, cursors, icons, hooks, accelerators, monitors, keyboard layouts, and
other internal objects. They are unmanaged resources. We should override the
Dispose method of our customized control or class and freeing all the
unmanaged resources in this method.
Hope this makes sense to you. Have a good weekend!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.