Hi, I've written an extension in C to sum jsonb. For that I use the jsonbiterator defined in https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/jsonb_util.c#L743 In the comments of JsonbIteratorNext it states: 'Callers in such a scenario, that are particularly sensitive to leaking memory in a long-lived context may walk the ancestral tree from the final iterator we left them with to its oldest ancestor, pfree()ing as they go' In the extension that I've written, I sometimes stop in the middle of an iteration, but only to raise an error (if the json contains a not numeric value), with 'ereport(ERROR, ...' Do I have to free the memory in that case? According to this guide to write extensions (http://big-elephants.com/2015-10/writing-postgres-extensions-part-i/) it wouldn't be necessary because 'Memory allocated by palloc will be freed automatically at the end of each transaction'. So if I understand it correctly I wouldn't have to. Thanks -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general