The more I think about it, the less correct it seems to me to have the statement to restore statistics tracked via ArchiveOpts->createStmt. We use that for DDL, but this really is data, not DDL. Because we store it in ->createStmt it's stored in-memory for the runtime of pg_dump, which means the peak memory usage will inherently be quite high.
I think the stats need to be handled much more like we handle the actual table data, which are obviously *not* stored in memory for the whole run of pg_dump.
I'm at the same conclusion. This would mean keeping the one getAttributeStats query perrelation, but at least we'd be able to free up the result after we write it to disk.