473,387 Members | 3,033 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,387 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 2257
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.