If we have a case in which there is a long running durable subscription that is consuming less messages than a producer is creating. If the durable subscription then decides to unsubscribe the kahadb will perform a cleanup. As part of the cleanup it will determine all messages that will no longer be consumed. During that process it will start a single transaction and process all of those messages at once. If there are more messages than there is available memory then the broker will generate a oom exception.
The kahadb should process the purging process through one or more transactions depending on the size of messages that need to be purged.