Every one of those calls is creating a whole new string. Strings are immutable, so whenever you think you are changing one, you are actually abandoning it and creating a new one with the changes. Abandoning the one string doesn't remove it, and in your case, it almost certainly means that not only has it not been deleted, but it CAN'T be deleted, so the old string and the new string remain in memory. That is probably what is killing the memory. You are probably creating at least two, and possibly more, strings of the full size with each call to Replace.

As for what to do...on that I have no good idea as long as you can't come up with a way to work on parts of the string rather than the whole thing.