-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R-package] R memory leaks #4282
Comments
Thanks for writing this up!
Are you referring to https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Condition-handling-and-cleanup-code? In the future, we'd very much appreciate if you included relevant links or supporting evidence when opening issues like this or leaving comments like #4273 (comment). |
Yes, that's what I was referring to. |
Ok perfect, thanks very much! |
* fix R memory leaks * attempt at solving linter complaints * fix compilation on windows * move R_API_BEGIN to correct place * make sure exception objects reach out of scope * better way to solve rchk complaints * remove goto statement
This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
There are some situations in which the R version can leak memory by not destructing C++ objects that become unreachable:
Class$new(...)
, like it is done when creating a dataset), the finalizer will not be called, thus leaking the C++ object (e.g. a dataset or a model). This could be solved by setting the finalizer in the R external pointer object itself.LightGBM/R-package/src/lightgbm_R.cpp
Line 203 in 8937022
LightGBM/R-package/src/lightgbm_R.cpp
Line 507 in 8937022
LightGBM/R-package/src/lightgbm_R.cpp
Line 683 in 8937022
LightGBM/R-package/src/lightgbm_R.cpp
Line 706 in 8937022
If the allocation of the R vectors fail, it will trigger a long jump which would leave the C++ vectors that were allocated before undestructed and unreachable. This could be solved by using unwind protection as described in the R extensions manual.
Rf_error
also triggers long jumps. Could either change it to something else while throwing the error on the R side, or add unwind protection for those too.The text was updated successfully, but these errors were encountered: