On Sat, Nov 16, 2013 at 11:59 AM, spir <denis.s...@gmail.com> wrote: > Hello, > > say a function defines 4 pointed elements of data. Depending on logical > conditions, one of them escapes the func to be assigned to some world > variable (static or on heap), while another is returned. How does Rust > determine which of those data are to be freed? Seems this can only be done > dynamically, at runtime, or do I miss a relevant point? Is there a cheap > algo to do this? > (Also, those elements of data can be arbitrarily complex, and hold other > pointed data which themselves may be placed there conditionally.) > > Thank you, > denis
The destructor is called when a variable goes out of scope. If the variable is moved from, the destructor isn't called. Borrowed pointers are just pointers at runtime without any dynamic checks, because the lifetimes are verified as part of type checking. There's never something like implicit extension of the lifetime of a variable beyond a scope. Shared ownership can be built on top of the ownership system like the `std::rc::Rc` type does, where the destructor only decreases a reference count rather than freeing an allocation. Moving around a reference counted pointer does *not* cause reference counts though. _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev