From 22675cd8dc75d8b8d4b0f818f5b093efbc364802 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Fri, 8 Aug 2025 22:44:15 +0200 Subject: vault backup: 2025-08-08 22:44:15 --- Data must outlive any references to it.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Data must outlive any references to it.md (limited to 'Data must outlive any references to it.md') 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 -- cgit v1.2.3