Heap size salesforce is a common, yet neglected problem whenever it comes to Salesforce Apex development. Salesforce heap size is the count of memory used by the variables, object instances in an Apex class.
In order to store these objects & variables, memory is allocated in Salesforce which is derived from allocated Heap. The Salesforce Heap size truly depends on the type of transaction, Salesforce provides a heap size limit of 6MB for synchronous transaction and 12 MB for asynchronous transaction.
Whenever, too much data is stored during processing an error occurs prompting Apex heap size too large. You must have encountered this error at least once if you are a developer.
Here are a few tips to ensure that the heap limit does not exceed the maximum size and your code runs smoothly