Closed
Description
I have a download function:
pub(crate) async fn download_music(url: &str, path: &str) -> Result<(), surf::Exception> {
if url.starts_with("http://") || url.starts_with("https://") {
let music_url = url.replace("https:", "http:");
let client = surf::Client::new();
let buffer = client.get(&music_url).recv_bytes().await?;
if !buffer.is_empty() {
fs::write(path, &buffer).await?;
}
}
Ok(())
}
Executing with task :: spawn will cause a significant increase in memory usage and will not be released after the download is complete.
for _ in 0..100 {
task::spawn(async {
let url = "https://***.mp3";
download_music(url, "***.mp3").await.ok();
});
}
With task :: block_on there is no memory leak.
for _ in 0..100 {
task::block_on(async {
let url = "https://***.mp3";
download_music(url, "***.mp3").await.ok();
});
}
Metadata
Metadata
Assignees
Labels
No labels