Oddbean new post about | logout
 no its enforced at compile time. Lifetimes are typechecked by the compiler. If you try to keep a note alive longer than a transaction it won’t compile. 
 How can the lifetime be checked at compile time? Magic?
The only thing I can think of is working with worst case scenario lifetimes by using the declaration scopes. 
 Its not that hard:

{
  let txn = Transaction::new()
}

In this case the compiler knows when it will be deconstructed. If note holds a reference to this beyond this scope then it is easily caught by the compiler. The ‘a parameter links the two references and can catch when one outlives the other. 
 I'm thinking that you can have code that conditionally at runtime might destroy an object and free its memory.
Probably rustc just assumes the worst 
 I don’t think you can explicitly do this in rust except in an unsafe block