开发者

OutOfMemoryException - Strategies to overcome this problem?

开发者 https://www.devze.com 2023-03-26 16:42 出处:网络
First of all, I am aware that开发者_Python百科 this question has been discussed many times in this forum, such as

First of all, I am aware that开发者_Python百科 this question has been discussed many times in this forum, such as Large array C# OutOfMemoryException and OutOfMemoryException

The object I am having problem with is

Dictionary<long, Double> results

which stores ID in long and calculation result in Double

I will have to reuse the same object about 10~20 times, every time when I reuse it I will call a

results = new Dictionary<long, Double>

I know that I can write it to a text file or database file for further processing but if possible I would try to avoid that as it is way too slow for the amount of data I handling. I have also tried GC.Collect() but no luck with that.

Can anyone with some previous experience give some pointer on this?

Edit: I have > 3 million objects in the list, but they are fixed (i.e. the key is the same in all iterations)


Ah - no. Makes also little sense to get out of memory exceptions in your calls.

I STRONGLY suggest you get serious in analysing - put a memory profiler onto the program and find the real problem. a long/double combo makes zero sense unless you store some hundred million pairs, and even then....

And: A moe to 64 bit is always wise. The 2 / 3 gb limit per process is harder on .net due to GC "overhead" - impossible to use up all the memory. 64 bit has much higher limits.

But again, your indication is wrong. The new Dictionary likely is NOT the error at all, something else wastes your memory.


if the issue is simply that the memory isn't being freed as expected; perhaps if you use ".Clear()" on the dictionary rather than re-creating every time?


Rather than creating 20 different instances, use one, but clear the list (which allows the GC to collect old elements) so that you have more memory to work with. Also, moving to a 64 bit environment might be wise if you require huge amounts of memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消