OutOfMemoryException in Regex Matches when processing large files

后端 未结 3 1529
野的像风
野的像风 2020-12-18 12:30

I\'ve got an exception log from one of production code releases.

System.OutOfMemoryException: Exception of type \'System.OutOfMemoryException\' was thrown.
          


        
3条回答
  •  春和景丽
    2020-12-18 13:05

    Without seeing your Regex, I don't know for sure but sometimes you can get problems like this because your matches are Greedy instead of Lazy.

    The Regex engine has to store lots of information internally and Greedy matches can end up causing the Regex to select large sections of your 800k string, many times over.

    There's some good information about this over here.

提交回复
热议问题