473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CollectionBase Clear - Nested collections?

I have created a collection class derived from CollectionBase that can be
nested several layers deep. so my root object has several child objects,
each of which has several grandchild objects, and so on. (The structure is a
GoF Composite.)

If I call the CollectionBase.Clear method on the root object, will it
release all child and grandchild objects for garbage collection, or will it
release only the root-level children. In other words, do I need to call
Clear just on the root object, or do I need to traverse the structure and
call Clear on each object in the structure? Thanks.

--
Dave Veeneman
Chicago
Nov 16 '05 #1
1 2251
Dave Veeneman <da****@nospam.com> wrote:
I have created a collection class derived from CollectionBase that can be
nested several layers deep. so my root object has several child objects,
each of which has several grandchild objects, and so on. (The structure is a
GoF Composite.)

If I call the CollectionBase.Clear method on the root object, will it
release all child and grandchild objects for garbage collection, or will it
release only the root-level children. In other words, do I need to call
Clear just on the root object, or do I need to traverse the structure and
call Clear on each object in the structure? Thanks.


Objects are eligible for garbage collection if there are no more
reachable references to them. If the only references to the
"grandfather" objects were the ones in the CollectionBase, then
clearing the CollectionBase will effectively make the whole tree of
objects orphaned, and they'll be eligible for garbage collection. Of
course, if any of those objects are referenced elsewhere, those
particular objects (and any objects they reference in turn) won't be
garbage collected.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
2
by: wael radwan | last post by:
how to customize the serialization of a collection that inherited form CollectionBase i.e making the class implementing ISerializable interface because when deserializing using the desrializing...
1
by: Dave Veeneman | last post by:
I have created a collection class derived from CollectionBase that can be nested several layers deep. so my root object has several child objects, each of which has several grandchild objects, and...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
1
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties...
2
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count,...
0
by: Marc | last post by:
Hi, I'm trying to create the schema (XSD) for a class that inherites from System.Collections.CollectionBase, and indicate the ElementName of the root and every item. This is an example: ...
1
by: jc | last post by:
RE: Why use a CollectionBase class here vs dataset or dataview? I'm looking at some vb.net 2005 code that was generated from a homegrown Codesmith Template that generate all of the retreival and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.