R Under development (unstable) (2024-10-31 r87283 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.5.0 R.methodsS3_1.8.2 R.oo_1.27.0 ---------------------------------- > > # Remove 'x' so that it will be finalized below > rm(x) > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 384402 20.6 795821 42.6 629851 33.7 Vcells 691822 5.3 8388608 64.0 2037757 15.6 > > 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.5.0 R.methodsS3_1.8.2 R.oo_1.27.0 ---------------------------------- > > message("TESTING: finalize() on Object without attach ... DONE") TESTING: finalize() on Object without attach ... DONE > > options(oopts) > > proc.time() user system elapsed 0.26 0.10 0.37