function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Subin009Subin009 

Apex heap size too large: 12239748.

While running the batch Apex I got this error "Apex heap size too large: 12239748"
Best Answer chosen by Subin009
TechingCrewMattTechingCrewMatt
You cn start by decreasing the heap size wherever possible. For example
for(Object rows: rowsList)
Can become
for(Object rows : (Object[]) rowsMap.get('rows'))
which will cause the list to be removed from the heap after the loop is finished.

How are you executing the batch? What happened when you decreased the scope argument?
 

All Answers

TechingCrewMattTechingCrewMatt
Would you please share the code?
TechingCrewMattTechingCrewMatt
Thanks. On what line is the error thrown?
Subin009Subin009
Not mentioning any lines, just throws Apex heap size too large: 12239748.
TechingCrewMattTechingCrewMatt
In the logs, you should see where debugged the getRecordsHelper method. Do you see the number of debugs that you were expecting? Also, for every batch there will be a separate transaction for start, finish, and every time the execute method runs. On which of these methods is the error thrown?

How are you executing this batch? You can try decreasing the scope argument in the Database.executeBatch() call to see if th problem is with the number of integers being processed in the execute method.
Subin009Subin009
User-added image
TechingCrewMattTechingCrewMatt
You cn start by decreasing the heap size wherever possible. For example
for(Object rows: rowsList)
Can become
for(Object rows : (Object[]) rowsMap.get('rows'))
which will cause the list to be removed from the heap after the loop is finished.

How are you executing the batch? What happened when you decreased the scope argument?
 
This was selected as the best answer
Shobit GuptaShobit Gupta
Please remove all the system.debug statement from for loops. This worked for me.