About this question
I'm trying to send a lot of data from Apex to VisualForce Page via JS remoting because I want to create an Excel file , so just for testing purpose I uploaded a text file (4.87 MB, 5110400 Characters) as a static resource I got the file in Apex added it to a list of string.
Problem
I added the body of Static Resource to the list twice, below is my Apex and VisualForce code:
Apex Class:
public with sharing class HeapSize_Controller { @remoteAction public static List
VisualForce Page:
Now the heap size in Apex is 10.22 MB (as per Debug logs) [removed] var j$ = jQuery.noConflict(); j$(document).ready(function() { getData(); }); function getData() { Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.HeapSize_Controller.generateRandomObject}', function(result, event){ if (event.status) { console.log('======= List :: '+ result); } else { console.log('======= Error Message :: '+ event.message); } }, {escape: true,buffer: false} ); } [removed]
But, when the page is loaded the remoting throw this error:
Why? Is it failing because the Synchronous Limit for Heap Size is 6MB? Then why does the remote say it's exceeding 15 MB?
And when I do this in my Apex method,
//String body = sr.Body.toString(); fileData.add(sr.Body.toString()); fileData.add(sr.Body.toString()); System.debug('========== Heap Size :: ' + Limits.getHeapSize());
The heap size now is 15.33 MB, even though I only added it twice to the list.
I then went ahead and did this:
//String body = sr.Body.toString(); fileData.add(sr.Body.toString()); fileData.add(sr.Body.toString()); sr = new StaticResource(); System.debug('========== Heap Size :: ' + Limits.getHeapSize());
Which made sense when I saw the debug logs, the heap size now was 10.22 MB again. which leads me to believe that object sr holds about 5 MB? Can someone please help me understand? Doesn't Remoting response handle upto 15 MB data? The Documentation says so.