From the MSDN docs on list.Clear()
Count is set to 0, and references to other objects from elements of the collection are also released.
From what I've been taught (which could be wrong), disposed & released are different things. Disposed means the items is completely removed from memory, released means it's simply not bound to that list by pointer.
Does that mean that I need to do
foreach (var item in Items)
{
item.Dispose();
}
this.Items.Clear();
If I effectively want to completely destroy/clear/release/dipose a list from existence?
To me it should all be as simple as .Clear()
, but, it's a bit unclear to me (pun intended) if that is enough and correct.
Note that we are not overriding Dispose()
nor Clear()
, it's all default implementation.
Also, the list is a List<T>
.
Edit : As per comment recommendation, I've went and checked, the items are all IDisposables
, which sheds some light on the fact that they should be disposed
Duplicate clarification on What is IDisposable for? :
I do not think these two questions are the same, mine is asking a difference between two things, the other is asking for clarification on one of those things. It also did not appear in my search before I decided to write the question, because I was too focused on keywords like "difference dispose vs clear", which will probably also be the case for future developers looking for an answer. I'll concede that the other answer provides some more information and is a good link to add here.