Imagine a scenario where there is a function that takes a very large matrix M
as one of its inputs. The function performs some action on M
obtaining another matrix which is then used for a subsequent step programmed in the function. If M
is only used once in the function, is it possible to execute an instruction from within the function that completely deallocates M
from memory?
I know that doing something like M <- NULL
inside the function will not deallocate M
in the global environment of R, in fact I can't think of any way that comes remotely close to achieving what I'm describing here. It would be weird as the user would find his inputs gone once the function finishes executing, but this would be beneficial for processes that handle large data structures.