I have a .NET 3.5 Application
- A function is running a million times
- It's doing search & replace & regex operations in 1MB+ strings (different sized strings)
When I profile the application I can confirm these strings are stored in LOH but also they are reclaimed by GC later on, so at a given time only max 10 of them are in LOH (10 thread is running).
My understanding is, these big strings are located in LOH, then getting reclaimed by GC but yet somehow due to their allocation locations (and being in LOH so not getting compacted) this causes fragmentation. This is happening despite of there is no memory leak in the operation.
It doesn't cause a problem in ~100K times however when it reaches to 1M+ it gives out of memory exceptions.
I'm using ANTS Memory Profiler and this is the result that I got in the early executions:
.NET Using 70MB of 210MB total private bytes allocated in to the application
Number of Fragments: 59
Number of Large Fragments : 48 (99.6% of free memory)
Largest Fragment: 9MB
Free Space: 52% of total memory (37MB)
Unmanaged Memory: 66% of total private memory (160MB)
- Do you think my diagnosis are correct based on the data in hand?
- If so, how can I solve this LOH Fragmentation problem? I have to process those strings and they are big strings. Should I find a way to split them up and process like that? In that case running regex etc. in split strings will be really challenging.