Animal
Animal
CC#
Created by Animal on 6/7/2023 in #help
❔ Out of memory exception
Hello, I have the following code private static void StringBuilderTest() { ConcurrentDictionary<int, string> concurrentDictionary = new ConcurrentDictionary<int, string>(); for (int i = 0; i < 1500; i++) { concurrentDictionary[i] = getBigStringWith60KCharecters(); } int counter = 1; Collection<int> ids = new Collection<int>(); StringBuilder caseExpression = new StringBuilder(); try { foreach (KeyValuePair<int, string> keyValuePair in concurrentDictionary) { ids.Add(keyValuePair.Key); caseExpression.AppendLine($"WHEN Document_Id = {keyValuePair.Key} THEN {keyValuePair.Value}"); const int MAX_PREFERD_AMOUNT_OF_CHARECTERS = 100000000; if (caseExpression.Length > MAX_PREFERD_AMOUNT_OF_CHARECTERS || counter == concurrentDictionary.Count) { string tempString = caseExpression.ToString(); TryUpdateBatchOfWebDocuments(tempString, ids); caseExpression.Clear(); ids.Clear(); } counter++; } } catch (Exception exc) { throw; } } The code in question involves the manipulation of strings using both the string and StringBuilder classes. From my understanding, neither the string nor the StringBuilder object is reaching its maximum capacity, which is approximately 2 billion characters. Despite this, I am still encountering the memory exception. I am wondering if there could be any other factors contributing to this issue. Are there any limitations on the maximum capacity of virtual memory that I should be aware of?
7 replies