Skip to content
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

R6 $finalize() methods #20

Closed
wlandau opened this issue Apr 8, 2020 · 3 comments
Closed

R6 $finalize() methods #20

wlandau opened this issue Apr 8, 2020 · 3 comments

Comments

@wlandau
Copy link
Collaborator

wlandau commented Apr 8, 2020

For memory efficiency.

@wlandau
Copy link
Collaborator Author

wlandau commented Apr 8, 2020

...especially with #19.

@wlandau
Copy link
Collaborator Author

wlandau commented Apr 11, 2020

@wlandau
Copy link
Collaborator Author

wlandau commented Apr 11, 2020

Actually, R is smart enough to free memory on garbage collection even when we go heavy on reference semantics. We will need a finalizer for the metadata database, but probably not in other situations.

> mem_used()
101 MB
> x <- runif(1e8)
> mem_used()
901 MB
> a <- init_target()
> a$get_cache()$set_value("x", x)
> b <- init_target()
> b$get_cache()$set_value("x", x)
> rm(x)
> gc()
            used  (Mb) gc trigger   (Mb)  max used
Ncells   1369770  73.2    2067778  110.5   2067778
Vcells 103072729 786.4  151019151 1152.2 103222981
        (Mb)
Ncells 110.5
Vcells 787.6
> mem_used()
901 MB
> rm(a)
> mem_used()
901 MB
> gc()
            used  (Mb) gc trigger   (Mb)  max used
Ncells   1369533  73.2    2067778  110.5   2067778
Vcells 103072906 786.4  151019151 1152.2 103222981
        (Mb)
Ncells 110.5
Vcells 787.6
> mem_used()
901 MB
> rm(b)
> gc()
          used (Mb) gc trigger  (Mb)  max used  (Mb)
Ncells 1369203 73.2    2067778 110.5   2067778 110.5
Vcells 3072857 23.5  120815321 921.8 103222981 787.6
> mem_used()
101 MB
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant