Skip to content

Error registering finalizer

3 messages · Paul Roebuck, Brian Ripley

#
What exactly is a reference object? I'm getting this error
message attempting to register a finalizer:

        can only weakly reference/finalize reference objects

I don't see any problem with the code... Here's what appears
to be the relevant portions.


setClass("PDNNObject",
         representation(handle = "externalptr",
                        id     = "character",
                        "VIRTUAL"),
         prototype=list(handle = NULL))
setClass("ProbesetGE",
         representation("PDNNObject"))

----

static void ProbesetGE_finalizer(SEXP vntData)
{
    Rprintf("In ProbesetGE_finalizer()\n");
    /* Deallocate memory of structure fields */
}

static SEXP AllocateProbesetGEPtr(unsigned count)
{
    return R_AllocatePtr(count,
                         sizeof(ProbesetGE_t),
                         ProbesetGETypeTag));
}

SEXP R_PDNN_newProbesetGE(unsigned count)
{
    SEXP vntObj;
    SEXP vntClassDef;
    SEXP vntData;
    SEXP vntAttr;
    SEXP vntHandle;
    unsigned n = 0;

    PROTECT(vntClassDef = MAKE_CLASS(PROBESET_GE_CLASS_NAME)); n++;
    PROTECT(vntObj      = NEW_OBJECT(vntClassDef)); n++;
    PROTECT(vntHandle   = AllocateProbesetGEPtr(count)); n++;
    SET_SLOT(vntObj, HandleSlotSymbol, vntHandle);

    PROTECT(vntData = R_ExternalPtrProtected(vntHandle)); n++;
    PROTECT(vntAttr = NEW_INTEGER(1)); n++;
    INTEGER(vntAttr)[0] = count;
    SET_COUNT(vntData, vntAttr);
R_RegisterCFinalizer(vntData, (R_CFinalizer_t)ProbesetGE_finalizer);

    UNPROTECT(n);

    return vntObj;
}


Thanks for any pointers...

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)
#
On Tue, 26 Jul 2005, Paul Roebuck wrote:

            
Still don't have an explanation for the above but the code
now works with the following mods.

-static void ProbesetGE_finalizer(SEXP vntData)
+static void ProbesetGE_finalizer(SEXP vntHandle)

-R_RegisterCFinalizer(vntData, (R_CFinalizer_t)ProbesetGE_finalizer);
+R_RegisterCFinalizer(vntHandle, (R_CFinalizer_t)ProbesetGE_finalizer);

Original thought was that a finalizer was a routine that
ran prior to an object's destruction (like a destructor).
Apparently, only certain objects can have finalizers.

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)
#
On Tue, 26 Jul 2005, Paul Roebuck wrote:

            
Do you have a reference for where you got that from?
Yes.  See http://www.stat.uiowa.edu/~luke/R/references.html (linked off 
the developer site).