diff options
Diffstat (limited to 'Data must outlive any references to it.md')
-rw-r--r-- | Data must outlive any references to it.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Data must outlive any references to it.md b/Data must outlive any references to it.md new file mode 100644 index 0000000..162bf30 --- /dev/null +++ b/Data must outlive any references to it.md @@ -0,0 +1,14 @@ +[[Pointer safety principle]] +[[Variables are subject to permissions similar to files on linux]] +[[Lifetime specifier]] +[[When heap data is deallocated]] +[[Variables lives on the stack]] +[[Ownership]] + +This is literally talking about heap data and references (ie `&String`): the heap data must not be freed when we try to use a reference to it. + +This is enforced in one of two ways. + +Firstly, if a reference is created to a variable it loses its Own permission: thus we can't drop it, because the compiler expects that permission on the place where it is dropped. + +Secondly, it uses the Flow permission and requires a a lifetime specifier when we return things from functions.
\ No newline at end of file |