rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.34k stars 616 forks source link

Memory leak with LocalFutureObj when not using Boxed futures #2748

Closed EricRnR closed 1 year ago

EricRnR commented 1 year ago

When using LocalFutureObj directly, the drop on LocalFutureObj here refers to the one of the empty drop function implementations such as here. The future will never be dropped, unlike the Boxed counterparts.

taiki-e commented 1 year ago

cc @Nemo157

Nemo157 commented 1 year ago

@EricRnR do you have a code example? The empty drop implementations are for borrowed instances, so they don't need to do anything, the owner will drop the values at some point after the LocalFutureObj stops borrowing them. Other owning types are expected to implement UnsafeFutureObj themselves like Box does.

EricRnR commented 1 year ago

Yes, this makes sense. For some reason I had convinced myself UnsafeFutureObj was not part of the public API and I had no hook into the drop. Crisis averted!