S
SharpCoderMP
hi,
until .net 2.0 i've been writing my own collections derived from
CollectionBase. Now with the generics it is much easier to do that...
but! i have some questions about generic lists of complex objects.
consider this short example:
class MyComplexClass : IDisposable
{
[some_fields]
Bitmap img1, img2;
Font font1, font2;
[and_so_on]
public void Dispose()
{
this.img1.Dispose();
this.img2.Dispose();
this.font1.Dispose();
this.font2.Dispose();
GC.SuppressFinalize(this);
}
}
now what happens when i create a list:
List<MyComplexClass> complexList = new List<MyComplexClass>();
and then use it heavily. What will happen when i clear my list?
complexList.Clear(); ???
when i was using CollectionBase i just overriden OnClear and before
clearing my collection i was calling Dispose method on each of my
objects in the list. so i was sure that memory *is* released.
do i have to implement my own generic list by using IList interface to
so make sere that all my complex objects are disposed on list clear?
until .net 2.0 i've been writing my own collections derived from
CollectionBase. Now with the generics it is much easier to do that...
but! i have some questions about generic lists of complex objects.
consider this short example:
class MyComplexClass : IDisposable
{
[some_fields]
Bitmap img1, img2;
Font font1, font2;
[and_so_on]
public void Dispose()
{
this.img1.Dispose();
this.img2.Dispose();
this.font1.Dispose();
this.font2.Dispose();
GC.SuppressFinalize(this);
}
}
now what happens when i create a list:
List<MyComplexClass> complexList = new List<MyComplexClass>();
and then use it heavily. What will happen when i clear my list?
complexList.Clear(); ???
when i was using CollectionBase i just overriden OnClear and before
clearing my collection i was calling Dispose method on each of my
objects in the list. so i was sure that memory *is* released.
do i have to implement my own generic list by using IList interface to
so make sere that all my complex objects are disposed on list clear?