Attempted to read or write protected memory. This is often an indication that other memory is corrupt
I have a application that clients connect to via socket. The application is multi threaded, does lots of number crunching, and consumes a huge ammount of memory. (1.5 - 2 GB) Occasionally it throws this error in a seemingly simple area of code.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Its not always on the same line, but its always in the same file, on a foreach loop. I'm wondering if theres some setting in VS 2008 thats causing it? Theres nothing weird going on it really just dies on a foreach loop iterating through a List. I'm pretty sure its not a threading issue because I am using lock() so i'm 100% sure that the Lists arnt getting modified by multiple threads at the same time. I've tried turning off compiler optimizations but it still does it every once in a while. Very annoying.
This is a very 开发者_如何转开发very rare occurance. I'm running the server in debug and this only happens like once every 12-48 hours.
"Theres nothing weird going on it really just dies on a foreach loop iterating through a List". - That sounds suspiciously like a threading synchronisation issue. (In fact, I can 99% guarantee it is!)
You probably need to take a copy of the list, if you have other threads attempting to modify it while you are iterating over it.
Suggest you post some code.
精彩评论