[Rd] Reference classes use a lot more memory after serialization/unserialization

From: Jan Mueller <Jan.Mueller_at_ipsos.com>
Date: Tue, 04 Sep 2012 08:56:11 +0100


Hello All,

I posted this earlier on R-help but received no answers. This touches the implementation of reference classes so maybe R-devel is a better place. The memory consumption of reference classes seems to increase dramatically (roughly 10x in the example below) with serialization/unserialization. S4 - classes are apparently not affected. Any ideas how this could be solved or at least circumvented?

Best
Jan

# start new R session, empty workspace

gc();
MySmallClass = setRefClass("MySmallClass",

       fields = list(
 myField = "numeric"

       ),
       methods = list(
    initialize = function(f) {
      myField<<- f;
           })

 );

# Generate 10K instances

o = lapply(rnorm(10000), MySmallClass$new)

gc()
s=serialize(o, connection=NULL)
gc();
p=unserialize(s);
gc();

Output:
1st gc():

         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 170895  4.6     350000  9.4   350000  9.4
Vcells 162042  1.3     905753  7.0   786155  6.0

2nd gc():
         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 720320 19.3     984024 26.3   899071 24.1
Vcells 588993 4.5 1162592 8.9 786155 6.0

3rd gc():

          used (Mb) gc trigger (Mb) max used (Mb) Ncells 720472 19.3 1166886 31.2 899071 24.1 Vcells 9941697 75.9 11298137 86.2 9941716 75.9

4th gc():

           used (Mb) gc trigger (Mb) max used (Mb) Ncells 6980212 186.4 7700734 205.7 6981388 186.5 Vcells 11744776 89.7 17456418 133.2 11754663 89.7

# Platform info:
# R version 2.15.1
# Platform: i386-pc-mingw32/i386 (32-bit)
# Binary package from CRAN
# Windows 7 32 Bit
# (I observed a similar behavior on Linux 64 Bit, same R version)



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 04 Sep 2012 - 08:29:33 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Sep 2012 - 11:20:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive