I have a newb question : I remove an element in a global list but I a function by using a return(). I saw that my other element still at his address (using inspect), but the object after the operation doesn't have the same tracemem. Maybe I don't understand tracemem but after my remove, did I move or copy something ?! I would like to parallelize some operations with a big data in a list object, remove the variable when I finish to free the memory so I want to be sure I work with the same object.
Thank you.
reference information : How can I remove an element from a list?
# WHEN YOU HAVE BIG DATA, after a process you want to free some memory of your
# object by remove a variable data
# E.G open a *.mat file with structured style -> list
#
# Try with big data and wait a while (your computer) to know
# object_size and mem_used()
#
#------------------------------------------------------------
#With Global Variable
x <- list('a'=123456789,'b'='highlander')
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))
# Remove data
x['a'] <- NULL
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))
#------------------------------------------------------------
# with function 1 - NOT WORKED
# FREE MEMORY
freeMemoryFromStructuredList1 <- function(x,select){
paste(length(x),object_size(x),mem_used(),tracemem(x))
x[select]<- NULL
}
#With Function 1
x <- list('a'=123456789,'b'='highlander')
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))
# TRy to Remove data
freeMemoryFromStructuredList1(x,'a')
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))
#------------------------------------------------------------
#With Function 2 (return) - WORK, Highlander at the same Address,
# but tracemem NOT
# FREE MEMORY
freeMemoryFromStructuredList2 <- function(x,select){
paste(length(x),object_size(x),mem_used(),tracemem(x))
x[select]<- NULL
return( x )
}
x <- list('a'=123456789,'b'='highlander')
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))
# Remove data
x <-freeMemoryFromStructuredList2(x,'a')
names(x)
paste(length(x),object_size(x),mem_used(),tracemem(x))
.Internal(inspect(x))