I had seen this error when I was processing tons of records on a virtual machine. My solution was breaking the query down into batches. That is, using a loop to only process about 5,000 a time. Do you happen to know how long your query would take to execute without the out of memory hangup?
----------------------------------------------------