R Under development (unstable) (2024-01-23 r85822 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > oopts <- options(warn=1L) > > message("TESTING: finalize() on Object without attach ...") TESTING: finalize() on Object without attach ... > > pkgs <- c("R.methodsS3", "R.oo") > isAttached <- function(pkgs) { + structure(sprintf("package:%s", pkgs) %in% search(), names=pkgs) + } > > # Record which packages were attached from the beginning > # (happens if not a fresh session) > wasAttached <- isAttached(pkgs) > > > assertPackages <- function(loaded=c("R.methodsS3", "R.oo")) { + s <- utils::sessionInfo() + s$R.version <- NULL + s$platform <- "" + s$locale <- "" + cat("----------------------------------") + print(s) + cat("----------------------------------\n\n") + loaded <- loaded[!wasAttached[loaded]] + stopifnot(!any(isAttached(loaded))) + } > > R.oo::setConstructorS3("MyClass", function(a=1:10) { + R.oo::extend(R.oo::Object(), "MyClass", a=a) + }) > > # Create an object with a finalizer > x <- MyClass() > > assertPackages() ---------------------------------- Platform: Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: character(0) time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_4.4.0 R.methodsS3_1.8.2 R.oo_1.26.0 ---------------------------------- > > # Remove 'x' so that it will be finalized below > rm(x) > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 377774 20.2 800652 42.8 633877 33.9 Vcells 679457 5.2 8388608 64.0 2002881 15.3 > > assertPackages(loaded="R.oo") ---------------------------------- Platform: Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: character(0) time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_4.4.0 R.methodsS3_1.8.2 R.oo_1.26.0 ---------------------------------- > > message("TESTING: finalize() on Object without attach ... DONE") TESTING: finalize() on Object without attach ... DONE > > options(oopts) > > proc.time() user system elapsed 0.29 0.03 0.31