Values aren't getting Dropped; where's the leak?

I'm writing a gRPC server in Rust using Tonic, and some of the methods return Streams. In order to understand the lifecycle of these requests and whether memory is getting leaked anywhere, I'm using the scopeguard crate to print messages when the Streams are getting dropped. I've also tried manually implementing Drop on some of these Streams.

In both cases, I'm seeing results that are difficult to interpret. Some parts of my streaming pipeline are getting Dropped when the client disconnects, and others aren't. These "leaks" aren't necessarily a problem from a performance perspective, it's more that I want to make sure I'm using the libraries correctly, and if memory is getting leaked, I suspect I'm not.

I gather than under normal circumstances (no panics), if drop() isn't getting called, that means somewhere, someone still owns the value. Is there any way I can see a sort of "ownership stack-trace" to understand why the value hasn't been Dropped?

Ideally I'd understand the ins and outs of the Tonic framework and it'd be clear where to look, but something that can at least point me in the right direction would be a huge help.

It's difficult to say with just what you've provided here. The classic thing that can cause memory leaks is a reference cycle, but it's not obvious that you would have those from what you describe.

One thing you might try is to instrument your crate with the tracing crate. It usually provides quite nice insights in how the application is running.

No.

Bummer. Thanks for the input!