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>:
A few additional details. According to Linux Programmer's Manual 1. http://man7.org/linux/man-pages/man3/mallopt.3.html 2. http://man7.org/linux/man-pages/man3/malloc_trim.3.html And if I understood everything correctly `free` could trigger `malloc_trim` based on value of several environment variables - MALLOC_TOP_PAD_ and MALLOC_TRIM_THRESHOLD_. However setting them as low as 1 or 0 doesn't have any effect (but as I wrote in previous email manual call of `malloc_trim` helps to release memory).
Regards Dmitriy Selivanov [[alternative HTML version deleted]]