r - How to clear memory used by rJava?

前端 未结 2 856
余生分开走
余生分开走 2021-02-05 16:38

I am using xlsx package to create workbook, worksheet, write data to the sheet and then save the workbook. However, when I repeat this set of actions for several times, I start

相关标签:
2条回答
  • 2021-02-05 17:06

    I do not know how to do it on xlsx, in fact I no longer use it because of those issues

    I now use XLConnect, and it has a command

    xlcFreeMemory()
    

    to do just that

    Please note that for best results you need to increase Java memory before youload it as follows

    options( java.parameters = "-Xmx4g" )
    library(XLConnect)
    

    Good luck

    0 讨论(0)
  • 2021-02-05 17:26

    Piggy-backing the above answer to note that you don't need XLConnect to accomplish the effects of xlcFreeMemory... just note that what xlcFreeMemory actually does is to run the following:

    gc()
    J("java.lang.Runtime")$getRuntime()$gc()
    

    That is, it runs gc() first in your R environment and then in the existing Java instance's environment.

    0 讨论(0)
提交回复
热议问题