Hi, Albe,
Thank you.
The resource is not memory, I have something like a file descriptor or network connection, which I believe is the common case for foreign table. Using RegisterXactCallback exposes an API at a much deep level to foreign table writer, and I need to find a place to anchor the context (fdw_state). I took a look at postgres_fdw and found that xact callback is exactly what is done. So I will take this approach.
Again, thank you Albe, for pointing me to it.
Feng