Related to my previous question: Preventing Memory issues when handling large amounts of text
Is
You really need to use a code Profiler. These will tell you exactly what's happening, where the memory is being used up, etc.
FYI: It's rarely where you think it is.