I'm storing a lot of objects in a List<T>. The number of objects can be very, very large, and is unknown beforehand. I also want to limit the memory usage of my application. Essentially the final goal is to sort the items.
What I want to do is this: when the total in memory size of the List<T> exceeds a certain size, I want to sort what I have so far, save them to disk, and continue with an external sorting algorithm. However, in order to do that, I need to know how much memory all the objects in the List<T> are using. Is that even possible in .Net? How would you solve this problem?