也许你可以gc()用? 如果可能的话,也许您可以将每个会话限制为某个内存阈值或某个超时?您可以在下面看到每个会话占用了多少内存。另请查看进程中的任务管理器,该进程占用了多少空间(注意:当前示例大约需要每个会话)observeinvalidateLater440Mb
rm(list = ls())
library(shiny)
cleanMem <- function(n=10) { for (i in 1:n) gc() }
runApp(list(
ui = fluidPage(
tableOutput('foo')
),
server = function(input, output,session) {
observe({
# periodically collect
invalidateLater(1000,session)
cleanMem()
})
x1 <- 1:100000000
x2 <- rbind(mtcars, mtcars)
env <- environment() # can use globalenv(), parent.frame(), etc
output$foo <- renderTable({
data.frame(
object = ls(env),
size = unlist(lapply(ls(env), function(x) {
object.size(get(x, envir = env, inherits = FALSE))
}))
)
})
}
))
Run Code Online (Sandbox Code Playgroud)