Skip to content

data.table issues with reference counting #4093

@mattdowle

Description

@mattdowle

Hi Matt,

I spent an entire day tracking down an issue that turns out to be a
problem in the data.table internals. Here is a simple reproducible
example:

library(data.table)
d <- data.table(x = c(1, 2), y = c(3, 4), z <- c(5, 6))
d[, x := NULL]
d[, y := NULL]
## .Internal(inspect(d, 1))
## @3234b40 19 VECSXP g0c7 [OBJ,REF(13),ATT] (len=1, tl=1027)
##   @354cde8 14 REALSXP g0c2 [] (len=2, tl=0) 5,6
## ...                         ^
## ...                         |_ zero refcount

After deletion of two leading columns the remaining column has
reference count zero. The reason is that in assign.c you use memmove
on the DATAPTR to shift remaining columns, which does not adjust
reference counts, and then use SET_VECTOR_ELT to replace a shifted
column by R_NilValue, which decrements the reference count the moved
column. You need to re-think this to work with reference counting.
Only modifying vector content with SET_VECTOR ELT is the safe and only
supported approach. You may need to make similar adjustments in other
places.

Best,
Luke

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions