as far as you have a reference to an object and you can access it in your code it is there in memory and garbage collector is not collecting it. so the answer is NO, they are kept in the memory
you can read more about garbage collection here.
if the code was like this
List<MyObject> MyList = new List<MyObject>();
MyList.Add(new MyObject());
MyList.Add(new MyObject());
then when you call MyList.Clear()
you have no reference to your created MyObject
s so garbage collector will collect them and delete them from memory in it's next run.
if you want to remove obj1
and obj2
from memory after clearing list you should use
obj1 = null;
obj2 = null;
GC.Collect()
but be aware of consequences of forcing garbage collection.