I am using Hashtable in my c# application. I am loading millions of key into, but after the application exceed the 3,7GB of RAM it gives me an "out of memory" exception.
I use x64 operation system, and the computer has 16GB of ram. I was thinking about maybe this could be an x86 limitation. I changed the build type to x64 but I still get the error.
Is there a maximum memory size for an object in .net? Can I do something to use all the memory?
Thanks, Andrew
Take a look on this previous answer: .NET Max Memory Use 2GB even for x64 Assemblies
The 2GB limit applies to each object individually. The total memory used for all objects can exceed 2GB.
Use a Dictionary<,>
instead of HashTable
. In a HashTable
both the key and value are objects, so if they are value types they will be boxed. A Dictionary
can have value types as key and/or value, which uses less memory. If you for example use an int
as key, each will use 28 bytes in a HashTable
while they only use 4 bytes in a Dictionary
.
If both the key and value are value types and use less than 8 bytes the Dictionary
will be able to hold more items than the HashTable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With