Created
June 15, 2014 05:06
-
-
Save davecheney/eba2a4ee2b89a992b8a3 to your computer and use it in GitHub Desktop.
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
| > On the other hand, you can see that &User literal escapes to heap. | |
| > What it means is that the literal value is used outside of the | |
| > function and therefore can’t be stored on the stack. This is always | |
| > the case when calling a method on a value and the method uses one or more fields. | |
| Not really, &User isn't a literal, User{ ... } is a literal, &User{ ... } is the address of a literal. The former cannot escape as only pointers/references can escape. | |
| The second sentence isn't correct. &User isn't a literal value, it's a pointer to a value. The value _could_ be stored on the stack, except a pointer to the value escapes the function, so the value has to to be moved to the heap to prevent the pointer referring to incorrect memory once the function returns. | |
| The last sentence is not correct. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment