I am sure that stringWriter is already very large, let's say a size more than 1 Gb and that your computer has a total memory of 2 GB. When you call ToString () the memory will get doubled because a new string will be created and allocated in heap of size 1GB to be able to copy the content of stringWriter. Try to avoid the unnecesary ToString () and try to do what you need to do using directly the stringWriter. Avoiding ToString(), normally you would decrease memory footprint by 50%.
But if you really need your data as string and you don't have sufficient memory, try to save the content first in a file, dispose the StringWriter and load the file content into a string using a StreamReader.ReadToEnd () API.
Another aproach would be to try to cut un chunks your serialized data and try to parse it in chunks. For example, let's consider an XML that has a structure like this:
<Root>
<Item>some data 1</Item>
<Item>some data 2</Item>
<Item>some data 3</Item>
....
<Item>some data n</Item>
</Root>
You could serialize your object into a MemoryStream, then read it in chunks and create "little" XML data from your chunks that looks like this:
First xml:
<Root>
<Item> some data 1 </Item>
</Root>
Second xml:
<Root>
<Item> some data 2 </Item>
</Root>
And so on, that could be checked individually and validated.