Skip to content
Prev 53837 / 63424 Next

Issue with memory deallocation/fragmentation on systems which use glibc

Dear R-devel mailing list and especially R-core, is there any chance to
receive feedback on issue I described in previous emails? I would consider
such behaviour as a bug.

As a work-around I've created small "clean-up" function:

malloc_trim_finalizer = function(e) {
  res = NULL
  if(R.version$os == "linux-gnu") {
    flog.debug("Calling malloc_trim(0L) to trigger glibc to release
memory\n")
    res = malloc_trim(0L)
  }
  res
}

And at the end of each function which produce a lot of intermediate small
objects I provide it to reg.finalizer():
some_function = function(...) {
  # do some useful work
  result = TRUE
  # register finalizer
  e = environment()
  reg.finalizer(e, malloc_trim_finalizer)
  return(result)
}

2017-06-22 11:12 GMT+04:00 Dmitriy Selivanov <selivanov.dmitriy at gmail.com>: