Created
April 6, 2019 13:43
-
-
Save brianmfear/dd5f9569b9a3644a803c309223fc6cc7 to your computer and use it in GitHub Desktop.
Example Reference and Heap Usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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