You mentioned you found methods that tell you how much memory is allocated
GC.GetTotalMemory(false);
- one of these methods (which, I believe, you have already found).
One thing I would like to point out from the MSDN documentation.
Retrieves the number of bytes that are currently considered allocated
This is at the very top of the documentation for the GC.GetTotalMemory method. I would like to indicate the word thought in the above phrase. Now I know that you know how to find the allocated amount, as it is mentioned in your question, however I will give this to illustrate that C # is a managed language. Using and consuming memory is distracting from you, and even GC methods are simply necessary to give you a vague idea of โโwhat is going on in your process. Working with memory levels manually sounds risky and unreliable to me.
I would recommend going with your original approach, but bringing the batch size back to level, so it is unlikely that you will get an exception from memory, no matter how many columns you work on. Think of hundreds, perhaps several thousand, not tens of thousands. Any performance gains that you get in large batches will likely outweigh the risk of memory problems at these levels, even if you try to find it. The performance tools mentioned in another answer would be a great way to determine how much batch size should be, and if that's even a problem.
Devin source share