You don't have to worry about it. As you suggested, garbage collection will take care of it for you. However, if you still have references elsewhere to any of the objects that were in your array, those objects, of course, won't be garbage collected.
I should also mention something about IDisposable
as suggested by the comments under your question. The .NET framework's garbage collector will release managed resources when appropriate. The purpose of the IDisposable
interface is to guarantee that unmanaged resources get released, such as open files and streams. If the class whose objects are in your array have any such unmanaged resources, the class should implement IDisposable
and you should call Dispose
on every object before you clear the array.
Normally when dealing with IDisposable
, you would utilize the using
statement to guarantee that the object was properly disposed when you're done with it. However, since you are dealing with a collection of disposable objects in this case, it's unlikely each object was created inside a using
statement (it could be possible in some extravagant scenario). Therefore, you must loop through the elements and call Dispose
on each one before you clear the array**. This, again, is only if the objects in your collection have unmanaged resources that need to be dealt with before each object is garbage collected.
** Keep in mind: you'll run into trouble if you have external references to any of those objects and try to use them again afterward since they will have already been disposed.