Thank you for your reply. The reason why I asked is that while memory
held by static hashtables in the Framework. Sometimes it's not clear to know
referenced from within the framework. I've had a similar case where
""Chris Lyon [MSFT]"" <clyon@online.microsoft.com> wrote in message
news:tPOz1ahVDHA.1948@cpmsftngxa06.phx.gbl...
> Niall,
>
> If you want the control to be collected, you'll need to sever all
> references to it. In this case, unbinding it. Although not required, the
> Dispose method is the recommended place for this.
>
> This isn't a memory leak in the Framework. The developer must put in the
> unbinding code, so that when Dispose gets called, the object is cleaned
up.
>
> -Chris
>
>
> --------------------
> >From: "Niall" <asdf@me.com>
> >Subject: Clear bindings on dispose of a control to allow GC to collect?
> >Date: Fri, 4 Jul 2003 11:52:34 +1000
> >Lines: 24
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> >Message-ID: <#Ber46cQDHA.1072@TK2MSFTNGP10.phx.gbl>
> >Newsgroups:
>
microsoft.public.dotnet.framework.clr,microsoft.public.dotnet.framework.wind
> owsforms.databinding
> >NNTP-Posting-Host: 64.215.221.9
> >Path: cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
> >Xref: cpmsftngxa09.phx.gbl
> microsoft.public.dotnet.framework.windowsforms.databinding:1157
> microsoft.public.dotnet.framework.clr:1332
> >X-Tomcat-NG: microsoft.public.dotnet.framework.clr
> >
> >I've been using the .Net Memory Profiler to chase down a memory leak in
our
> >application. A custom control we have written was not being collected
after
> >the form it was on was closed. Because the form tied to an event on that
> >control, the whole lot wasn't being collected.
> >
> >Using the profiler, I found out there was only one root path to this
custom
> >control. It was being referenced by a ComponentEntry which was being held
> in
> >a static Hashtable - TypeDescriptor.cachedComponentEntries. Examining the
> >allocation stack of that ComponentEntry showed that it was created when
the
> >custom control was bound and DataBindings.Add() was called. This lead me
to
> >think that perhaps if I ensured the control was unbound when it was
> >disposed, the reference would be broken and the control could be
collected.
> >So I put a DataBindings.Clear() in the dispose, and lo and behold, the
> >control got collected.
> >
> >So I am wondering... is it required/expected behaviour that a control
> unbind
> >itself when it is being disposed? Would there be any possible negative
> >effects from explicitly removing the bindings in the Dispose? Is this a
> Net
> >memory leak such that the framework code should recognise when the
control
> >is disposing and clear its cache, or perhaps use a WeakReference?
> >
> >Niall
> >
> >
> >
>
>
> --
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Use of included script samples are subject to the terms specified at
>
http://www.microsoft.com/info/cpyright.htm >
> Note: For the benefit of the community-at-large, all responses to this
> message are best directed to the newsgroup/thread from which they
> originated.
>