-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible memory leak involving warnings #7649
Comments
I think you'll need to provide more compelling evidence that this is a problem: library(dplyr, warn.conflicts = FALSE)
identity <- function(x, warn) {
if (warn) {
warning("fake warning")
}
x
}
df <- tibble::tibble(e = rep(1, 1e8))
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = TRUE))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `e = identity(e, warn = TRUE)`.
#> Caused by warning in `identity()`:
#> ! fake warning
lobstr::mem_used() - old
#> 9.58 MB
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = TRUE))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `e = identity(e, warn = TRUE)`.
#> Caused by warning in `identity()`:
#> ! fake warning
lobstr::mem_used() - old
#> 12.75 kB
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = TRUE))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `e = identity(e, warn = TRUE)`.
#> Caused by warning in `identity()`:
#> ! fake warning
lobstr::mem_used() - old
#> 11.25 kB
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = FALSE))
lobstr::mem_used() - old
#> 616 B
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = FALSE))
lobstr::mem_used() - old
#> 632 B
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = FALSE))
lobstr::mem_used() - old
#> 616 B
old <- lobstr::mem_used() Created on 2025-02-18 with reprex v2.1.1 |
I likely misused the term "memory leak" since repeated applications don't lead to an increase in memory usage. I think the issue is that library(dplyr, warn.conflicts = FALSE)
identity <- function(x, warn) {
if (warn) {
warning("fake warning")
}
x
}
df <- tibble::tibble(e = rep(1, 1e8))
old <- lobstr::mem_used()
rm(df)
lobstr::mem_used() - old
#> -800.00 MB
df <- tibble::tibble(e = rep(1, 1e8))
old <- lobstr::mem_used()
df <- df %>% mutate(e = identity(e, warn = TRUE))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `e = identity(e, warn = TRUE)`.
#> Caused by warning in `identity()`:
#> ! fake warning
rm(df)
lobstr::mem_used() - old
#> 7.99 MB Created on 2025-02-18 with reprex v2.0.2 |
I recently updated my
dplyr
version (late to the party), and I'm hitting some increased memory usage. I've traced it back to how warnings are handled. Beginning indplyr 1.1.1
, I get the following output:Created on 2025-01-31 with reprex v2.0.2
If I restart R and rerun with
warn = FALSE
, the final memory usage is only 7.9 MB rather than 772.8 MB. Additionally, if I rewrite the mutate to avoid using a pipe viadf <- mutate(df, e = identity(e, warn = TRUE))
, the final memory usage is only 8.8 MB. Switching the pipe to|>
also yields low memory usage. Underdplyr 1.1.0
, the above reprex yields 18.8 MB.I don't have a full appreciation for whether warnings would capture my environment, but I'm wondering if that's perhaps happening within either base R or dplyr's own record of warnings.
The text was updated successfully, but these errors were encountered: