Skip to content

Commit

Permalink
Fix leak when JIT compiles generator instances
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
lionel- committed Dec 3, 2021
1 parent 41e13e3 commit d265b14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# coro (development version)

* Fixed a leak that occurred via JIT caching (#36).


# coro 1.0.1

* `collect()` now preserves lists and data frames (#32).


# coro 1.0.0

This is the first public version of coro.
Expand Down
6 changes: 5 additions & 1 deletion R/generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ generator0 <- function(fn, type = "generator") {
env <- new_generator_env(env, info)
user_env <- env$user_env

# The compiler caches function bodies, so inline a weak
# reference to avoid leaks (#36)
weak_env <- new_weakref(env)

# Forward arguments inside the user space of the state machine
lapply(names(fmls), function(arg) env_bind_arg(user_env, arg, frame = generator_env))

Expand Down Expand Up @@ -190,7 +194,7 @@ generator0 <- function(fn, type = "generator") {
# environment.
env$jumped <- TRUE
out <- evalq(envir = user_env,
base::evalq(envir = !!env, {
base::evalq(envir = rlang::wref_key(!!weak_env), {
env_poke_exits(user_env, exits)
!!state_machine
})
Expand Down

0 comments on commit d265b14

Please sign in to comment.