rvk: the line of text is only stored in memory one at a time.
TFileStream writes out every line to disk. So there is nothing stored in memory.
So the heap problem isn't related to the TFileStream at all (unlike what TS expected).
The problem is probably in GetTextOfRecord.
Getmem & Gucao's remark that the query is somehow gigantic (and a query is much larger due to the variant use than the resulting bytes), and of course Warfley's remark to avoid 32-bti in the first place if you are a heavy memory user.
The TQuery wouldn't make a difference. It could handle milion and milion of records. And TFileStream can handle that too.
It's the GetTextOfRecord whic is the problem.
You can see from my example that TFileStream handles this just fine.
It creates a file of 0,5GB. Way more than the 4MB file TS creates when the heap crash happens.