Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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