A simple and hopefully easy memory optimization would be to discard commands older than n. Or maybe it could discard automatically when low memory is detected?