Container object

V

Viorel Ghilas

Hi all

I have a list of Componet objects and put them in Containner, after
container is disposed then components doesn't disposed

I write some code example
Component c = new Component();

using(Container list = new Container()) {
list.Add(c, "c");
ISite site = c.Site;
...
}

but after this code c is not null

but in Container dispose method look like this
protected virtual void Dispose(bool disposing)
{
ISite site1;
int num1;
if (!disposing)
{
return;
}
Container container1 = this;
lock (container1)
{
while ((this.siteCount > 0))
{
num1 = (this.siteCount - 1);
this.siteCount = num1;
site1 = this.sites[num1];
site1.Component.Site = null;
site1.Component.Dispose();
}
this.sites = null;
}
}why c is not null, if container dispose themwith best regardsViorel Ghilas
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Viorel,

The component is disposed. Disposing an object means that the object
probably freed some unmanaged resources. The object itself is still alive
and it is going to be alive until after there are no more references to it
and GC kick off and cleaned up the garbage. So, c will never be null in your
code.

There is no way using Component class to find out whether the componet has
been disposed. Controls, though, have property IsDisposed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top