Does rust drops object immediately after it last used or drop it when exits the current scope?
fn test() {
let x = "1".to_owned();
// does x drops here?
let y = "1".to_owned();
// or x drops here?
}
Does rust drops object immediately after it last used or drop it when exits the current scope?
fn test() {
let x = "1".to_owned();
// does x drops here?
let y = "1".to_owned();
// or x drops here?
}
Variables are always* only dropped at the end of their scope, in reverse order of declaration.
fn test() {
let x = "1".to_owned();
let y = "1".to_owned();
// y drops here
// x drops here
}
* of course variables that have been moved out of donβt actually drop anything. This is why manually calling βdrop(x)
β can be used to drop x
eariler.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.