Use the code below in your Apex code to monitor the heap during execution.
System.debug(LoggingLevel.Debug, 'Heap Size: ' + Limits.getHeapSize() + '/' + Limits.getLimitHeapSize());
Reference: https://help.salesforce.com/articleView?id=000170956&type=1