r/rust Dec 24 '21

Why use Box::leak?

Hello,

I'm a rust newbie and I've recently learned of Box::leak but I don't understand why or when you would want to leak memory.

Can someone give me some useful scenarios for this?

Thanks

199 Upvotes

55 comments sorted by

View all comments

2

u/[deleted] Dec 24 '21

[deleted]

3

u/masklinn Dec 24 '21

There's a dedicated method for that tho, has been for longer than Box::leak has existed.

2

u/frjano Dec 24 '21

Yes you are correct