Like any other large application .NET, my current project C#contains many collections .NET.Sometimes I don’t know from the very beginning what size the collection (List / ObservableCollection / Dictionary / etc.) Will be. But there are many times when I know what it will be.
.NET
C#
I often get OutOfMemoryException, and I was told that this can happen not only due to process size limitations, but also because of fragmentation.
OutOfMemoryException
So my question is this: does the collection size (using the capacity argument in the constructor) set each time I know that its expected size helps me prevent at least some of the fragmentation problems?
This quote from msdn :
If the size of the collection can be indicating the original ability eliminates the need to resize operations when adding items to the List.
But still, I don't want to start changing large parts of my code for something that might not be a real problem.
Did any of you solve your memory problems?
Specifying the initial size will rarely ever get rid of the OutOfMemory problem - if your collection size is not a million objects, then you really should not store such a collection.
. , , , .
, 99 100, , .
OOM, , :
, - , (, , , ). , , " ", .
, .
, . , ( ..) - , ; .
, x64 , 2 - , .
; , .
.NET , , , .NET. , (, GDI +, COM ..). , , . IIRC LOH, 80kb. , , 20 000 , .
, , , : OutOfMemoryExceptions? ? , WinDbg , , LOH.
, , . , , .
, . , .
LOH ( 80 kB). , . , , , .
, . . , , - .NET, , ?
, , , OOM. , , .