DimkaNewtown
Freshman
Here's my situation, I have a collection of objects which have collections of objects several levels deep. When I am done working with these objects I call .Clear() method on the topmost object. MSDN2 states that this method will clear the collection and release object members for garbage collection. Does this mean that it's recursive and child collections will also be released or will the subsequent children still be alive and kicking in memory?
In pseudocode it would look someething like this (assume all members are exposed correctly):
[csharp]
class A
{
Collection<B> _b;
}
class B
{
Collection<C> _c;
}
class C
{
somevar = 1;
}
main
{
Collection<A> collA = new Collection<A>();
//load collection and its children, do processing
//time to unload
collA.Clear();
}
[/csharp]
Would that work fine or do I need to go through each child collection manually clearing it?
[csharp]
main
{
Collection<A> collA = new Collection<A>();
//load collection and its children, do processing
//time to unload
collA.B.C.Clear();
collA.B.Clear();
collA.Clear();
}
[/csharp]
My concern are the dangling objects which won't be picked up by the garbage collector until far far later.
In pseudocode it would look someething like this (assume all members are exposed correctly):
[csharp]
class A
{
Collection<B> _b;
}
class B
{
Collection<C> _c;
}
class C
{
somevar = 1;
}
main
{
Collection<A> collA = new Collection<A>();
//load collection and its children, do processing
//time to unload
collA.Clear();
}
[/csharp]
Would that work fine or do I need to go through each child collection manually clearing it?
[csharp]
main
{
Collection<A> collA = new Collection<A>();
//load collection and its children, do processing
//time to unload
collA.B.C.Clear();
collA.B.Clear();
collA.Clear();
}
[/csharp]
My concern are the dangling objects which won't be picked up by the garbage collector until far far later.