Open GoogleCodeExporter opened 9 years ago
I just checked out the most recent version of the RPostgreSQL code from svn and
confirmed that the behavior is the same in the devel version of the code as
well (0.5-1 30-Jan-2014).
Original comment by rmcge...@gmail.com
on 16 Jul 2014 at 7:01
Ok, I now suspect that this may not be a bug, but caused by strangeness (or my
lack of understanding) in how R environments work. Read on if you want details,
but no action is required.
It seems that inside of a function, R sometimes will return both the object and
a pointer to the calling environment (the function). However, in the global
environment, the environment is not returned. If the calling environment has a
lot of other objects in it, I suspect that they may get copied as well when
serialize is run on an object inside a function, causing the serialized version
to be (much?) bigger than it would otherwise be, and thus causing the memory
error.
Notice the different behavior of returning list(a~b) either in the global
environment or inside a function. In the second case, the calling environment
is also returned (as a pointer, I believe). I suspect that this causes objects
in the calling environment to be copied into the serialize command inside a
function, but not in the global environment.
> list(a~b)
[[1]]
a ~ b
> test <- function() list(a~b)
> test()
[[1]]
a ~ b
<environment: 0x1a788f80>
## Note that the character representation is about 10% larger when the object
is
## returned inside a function.
> nchar(rawToChar(serialize(list(a~b), NULL, TRUE))
[1] 183
> ncharTest <- function() nchar(rawToChar(serialize(list(a~b), NULL, TRUE))
> ncharTest()
[1] 199
Thus, a possible explanation for the "bug" is that serialize is returning both
the large object plus a large environment of other objects that is legitimately
larger than my available contiguous memory or larger than some SQL
configuration parameter. Thus, I withdraw the previous report.
Thanks, Robert
Original comment by rmcge...@gmail.com
on 16 Jul 2014 at 10:30
Original issue reported on code.google.com by
rmcge...@gmail.com
on 16 Jul 2014 at 6:31