简体   繁体   中英

C# Out of Memory Diagnostics

I've looked at many articles but so far I cannot figure out how to better diagnose my problem. First, basic info.

Win7 64bit. 16 GB memory. When I get the out of memory exception Windows Task Manager says I'm using 7.4GB out of that 16 GB of memory. I have gone in app.config and added

  <gcAllowVeryLargeObjects enabled="true" /> 

but I don't think I'm making a 2GB object. GC.GetTotalMemory is tells me how much I'm using, but not how how much I have available... I can't find that method if it exists.

What I'm doing is reading from an SQL database 17,000 stock symbols. Each symbol has open,high,low,close,vol per day, going back to 1985. That is the maximum size; some symbols don't go back that far. So I create on object per stock, each object has a list of these open,high,low,closes. I keep all these objects in a List object... that's basically a pointer to thousands of objects so I doubt that's considered a large object.

From what I can see I shouldn't be getting this out of memory exception, but don't know what other tools I can use to see where this memory failure is coming from. Any other tips, tools out there I can use to try to figure out whats taking up so much space? Maybe there is some setting in visual studio that has a hard cap to how much memory it uses (doubt it)?

In VS2015, in the Diagnostics pane, you can get a memory snapshot of your entire heap. Make sure your program is in a break state, trigger the snapshot and look at the list you get. You'll even get information about every single object and what's inside!

Also the fact that you have a 64bit OS doesn't mean your application is 64bit. And if you're running out of memory on a 64bit application with 16GB of RAM, things are pretty dire.

Thanks for all the quick replies. I read in a couple places that if the build configuration manager was set to ANYCPU it would run 64bit if I had a 64bit OS, 32bit if not. Apparently I read wrong or it was wrong. I changed my platform to x64 and its now reading in all my data without OOM... so that has to be it.

Thanks... I feel stupid for not trying this first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM