0

I've read in some of the threads here to choose IEnumerable over IList to pass data from controller to views. Reason being IList is heavy for the view and I understand since we only iterate over the results, IEnumerable will be suffice.

But in comparision, IList has few additional properties and methods. I assume these execute only when they are called, meaning there is no stack memory consumed except a reference to the object on the heap. So, how to determine if the object is heavy for certain use in general.

Edit

I understand about their usage but can anyone provide more details on memory consumption, for why IList is considered heavy.

Sunny
  • 4,765
  • 5
  • 37
  • 72
  • I think it has less to do with memory use than with flexibility. Unless you're using an `IDataReader` or some other kind of cursor-based interface (which are normally not the best objects to be passing around arbitrarily), anything that implements `IEnumerable` is probably going to have an array or linked list at its heart, and so memory use will be comparable no matter what type you cast it to. – Jeremy Todd Apr 26 '13 at 03:27
  • It is also a little odd to talk about memory issues with interfaces since interfaces say nothing about implementation. – Jim D'Angelo Apr 26 '13 at 03:45
  • Yeah, although I can see the point that `IEnumerable` at least *allows* implementations that don't need to store all the data in memory, even if that's probably pretty rare in practice. – Jeremy Todd Apr 26 '13 at 03:48
  • Technically, IList could as well (it is an IEnumerable afterall). But I get your point. – Jim D'Angelo Apr 26 '13 at 03:50

1 Answers1

0

I would argue that a more primitive data structure can prevent developers from adding logic in their views that make use of rich features offered by more elaborate data structures. That's IMO an argument in favor of a simple data structure

TGH
  • 38,769
  • 12
  • 102
  • 135