[info-performer] Reference counting question

Date view Thread view Subject view Author view

From: Juan Manuel Cappi (jcappi++at++sol.info.unlp.edu.ar)
Date: 04/28/2004 12:47:26


Hi!

I have some doubts regarding the reference counting mechanism used
in Performer and I'm a bit confused.

I wrote the following code:

        pfText *text;
        pfString *str;

        pfInit();
        pfConfig();

        str=pfNewString(NULL);
        text=pfNewText();
        printf("%i\n" , pfGetRef(str)); //0
        printf("%i\n" , pfGetRef(text)); //0
        pfAddString(text,str);
        printf("%i\n" , pfGetRef(str)); //1
        printf("%i\n" , pfDelete(text)); //1 - Delete ok
        printf("%i\n" , pfGetRef(text)); //0
(1) printf("%i\n" , pfGetRef(str)); //1 ?!

Things went fine until the last line(1). According to the man-pages,
in the pfMemory definition it states: "pfDelete frees the memory
associated with mem if its reference count is <= 0. When an object is
freed, it decrements the reference count of all pfMemories that it
once referenced and will delete any of these pfMemories with reference
counts that are <= 0. Thus, pfDelete will follow all reference chains
until it encounters a pfMemory which it cannot delete.". From this
text I understood that line (1) should be 0, since the text deletion
should have decremented the string's reference count to 0 and then
deleted it. But, due to the behavior shown in the example, I guess
there is something I'm not getting right. I would be very grateful if
someone could help me with this issues:

Is something wrong with the code which is causing this "error"?

If this is the expected behavior; how can I know that "str" is no
longer referenced by a pfText in the case pfRemoveString is not called
before pfDelete?

In which cases the deletion of a pfMemory cause a cascade deletion?

Thanks in advance,

                  Juan Manuel
                  


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Apr 28 2004 - 12:35:04 PDT