Skip to content

Instantly share code, notes, and snippets.

@brianmfear
Created April 6, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianmfear/dd5f9569b9a3644a803c309223fc6cc7 to your computer and use it in GitHub Desktop.
Save brianmfear/dd5f9569b9a3644a803c309223fc6cc7 to your computer and use it in GitHub Desktop.
Example Reference and Heap Usage
// Technical Note: We can't add any strings to the debug logs
// because strings go in to a "string pool", which affects
// heap size for each non-unique string.
// Base heap
System.debug(Limits.getHeapSize());
// The "symbol table" has a new entry added, +0 heap
// i is defined, no value (heap does not change)
Integer i;
System.debug(Limits.getHeapSize());
// i now has a reference to an Integer 5 on the heap, +8 heap
i = 5;
System.debug(Limits.getHeapSize());
// j contains a reference to i, +0 heap
// If it were not a reference, it would have been +8 heap
Integer j = i;
System.debug(Limits.getHeapSize());
// j now has its own value, +8 heap
j = 10;
System.debug(Limits.getHeapSize());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment