Jack
Jack

Reputation: 10037

.Net: Is there a size limit on generic object list List(Of T)?

Is there a limit on how many object a list can hold?

Upvotes: 0

Views: 1064

Answers (6)

Alex
Alex

Reputation: 186

If you look at the count/item/etc property of the generic List (of T); it is an integer.

So i guess Integer.MaxValue (2147483647) is a good guess.

Upvotes: 3

leen
leen

Reputation: 9098

The .Count property of a list is an integer, so it's somewhat limited in this regard.

Upvotes: 2

Tacoman667
Tacoman667

Reputation: 1401

I believe it is limited to the amount of memory you have. The more you add to the List, the more items are added to the stack until the reference is released and the garbage collector grabs it back.

Upvotes: 0

GregC
GregC

Reputation: 8007

Please keep in mind that large collections might end up on Large Object Heap. This part of managed memory doesn't get cleaned up as well as Gen0,1,2, so please proceed with caution. Let the runtime select collection sizes based on the data that you actually need to add.

Upvotes: 0

Ben Collins
Ben Collins

Reputation: 20686

There's an easy way to find out :-)

int count = 0;
while (true)
{
    myList.Add(new object());
    Console.WriteLine("added " + count++ + " objects");
}

Upvotes: 2

James Gregory
James Gregory

Reputation: 14223

Only those imposed by your physical architecture, available memory etc...

Upvotes: 0

Related Questions