{"record":{"id":"472b51b7df262e40","repo":"dotnet/wpf","slug":"outofmemoryexception","errorCode":null,"errorMessage":"OutOfMemoryException","messagePattern":"OutOfMemoryException","errorType":"exception","errorClass":"OutOfMemoryException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Generic/Span.cs","lineNumber":232,"sourceCode":"                length = lc + _spanList[ls].Length - first;\n                lc += _spanList[ls].Length;\n                ls++;\n            }\n\n            // If no old Spans remain beyond area affected by update, handle easily:\n\n            if (ls >= Count)\n            {\n                // None of the old span list extended beyond the update region\n\n                if (fc < first)\n                {\n                    // Updated region leaves some of [fs]\n\n                    if (Count != fs + 2)\n                    {\n                        if (!Resize(fs + 2))\n                            throw new OutOfMemoryException();\n                    }\n\n                    Span<T> currentSpan = _spanList[fs];\n                    _spanList[fs] = new Span<T>(currentSpan.Value, first - fc);\n                    _spanList[fs + 1] = new Span<T>(value, length);\n                }\n                else\n                {\n                    // Updated item replaces [fs]\n                    if (Count != fs + 1)\n                    {\n                        if (!Resize(fs + 1))\n                            throw new OutOfMemoryException();\n                    }\n\n                    _spanList[fs] = new Span<T>(value, length);\n                }\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Generic/Span.cs#L214-L250","documentation":"During Span<T>.Set, when an updated region leaves part of an existing span ([fs]) intact, the span list must be grown by one via Resize. If Resize returns false (allocation failure), the code throws OutOfMemoryException to signal it could not complete the operation.","triggerScenarios":"Inserting/setting a range in a SparseSpanCollection that splits an existing span at an interior point while the internal span list cannot grow (its Resize fails).","commonSituations":"Very large or highly fragmented span collections exhausting internal capacity, e.g. extreme memory pressure while assembling large text runs.","solutions":["Reduce memory pressure in the process (free objects, use 64-bit, increase memory limits)","Batch span insertions so fewer splits/resizes occur","Treat as fatal allocation failure: catch OOM only to save state and exit gracefully"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// no pre-call validation available; monitor process memory before large layout operations\nif (GC.GetTotalMemory(false) > memoryBudget) { /* free memory first */ }","typeGuard":null,"tryCatchPattern":"try {\n    spanCollection.Set(value, length);\n} catch (OutOfMemoryException) {\n    // abort operation; release resources; do not retry in-process\n}","preventionTips":["Run memory-intensive layout in 64-bit processes","Limit the number/size of span insertions","Catch OOM only at top level to shut down cleanly"],"tags":["wpf","out-of-memory","internal","span"],"backgroundTag":"out-of-memory","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}