myFun <- function(largeObj, simEnv, objectNameInSimList) {
print(object.size(largeObj)) # it is big, and you can use it here
rm(list = objectNameInSimList, envir = simEnv)
# don't have to rm the largeObj because it will disappear at the end of this function
return("I have deleted a large object in the simList environment")
}
sim <- simInit()
sim$small <- rnorm(1)
sim$myLargeObject <- rnorm(1e7)
objSize(sim) # shows large object
myFun(largeObj = sim$myLargeObject, simEnv = envir(sim), objectNameInSimList = "myLargeObject")
objSize(sim) # shows large object is gone
gc() # should cause a change