In spite of memory quota, some document memory may not be released quickly enough by the GC. Backport changes like this or this to ensure that the GC picks up orphaned document memory blocks as quickly as possible.
MB-52526 Fix LET value usage and tracking
MB-57742 N1QL py-tpcc tests hit NewConnectionError on build 7.1.5-3867