Menu

#1 Root and parents need references

open-postponed
nobody
Core (11)
5
2002-12-04
2001-03-05
Daniel Rupe
No

The root metadata object and other parent (composite) metadata objects need to be reference
counted from within the composite and model group classes.

Consider the following scenario in the code:

-- the root is created from the factory
-- a metadata item such as CaptureConditions is obtained and has various sub-items created
-- the smart pointer to the root goes out of scope
-- calling getFullKey() on the CaptureConditions smart pointer causes an exception to get thrown

This has not yet been researched fully, so the following is not definite, but the most probable
cause for this is that the mParent pointer in the CaptureConditions composite is NULL, since
mParent is not a smart pointer, and since the root has gone out of scope. The same applies for
the parent pointer in the model group classes too.

George and I (Dan) discussed this and the only fix we have come up with so far is to make the
parent pointers in the composite and model groups classes be smart pointers instead of regular
pointers. This would result in a reference getting kept to the parent object (including the root) so
the objects would exist as expected for calls through the parents (such as getFullKey()).

Making the parent pointers be smart pointers though, would introduce a similar issue that was
found in Mma. Namely, the parent object having a smart pointer to the the child object, and the
child object having a smart pointer reference to the parent object would result in a memory leak,
since the smart pointers would not properly release each other.

George had the idea of making a callback to the root metadata object be made available to the
reference counting class. The reference class could call the callback method (if non-NULL) in
the root object. The root object could see if all its children have a reference count of only 1, and
if so, the root could decrement its reference count again. This would allow the use of smart
pointers as mentioned above.

Do non-root objects need to do anything special concerning their reference counts, or does that
issue apply only to the root?

Discussion

  • George Sotak

    George Sotak - 2001-03-06
    • labels: --> Core
     
  • Daniel Rupe

    Daniel Rupe - 2001-11-07

    Logged In: YES
    user_id=112680

    From an opened duplicate bug (#456920)...

    The bug seems to only happen in modelgroup test. To
    found the problem, place the following debug code in
    the beginning of
    PmtElement::createFromFactoryAndSetParentAndOccurrence:

    if (parent->key() != "PmtRootElement")
    {
    if (parent->parent() == 0)
    {
    char msg[100];
    sprintf(msg, "Error: parent of metadata(key: %
    s) is null", parent->key().c_str());
    cout << endl;
    cout << msg << endl;
    }
    }

    Compile and run interpretertest, the error message
    will come up in testModelGroup.

    This bug was found while refering to the parent of a
    non-root metadata in the new md factory design for
    namespace.

     
  • Daniel Rupe

    Daniel Rupe - 2001-11-07
    • priority: 5 --> 9
     
  • Daniel Rupe

    Daniel Rupe - 2001-11-07
    • assigned_to: nobody --> rupe
     
  • Daniel Rupe

    Daniel Rupe - 2002-11-04
    • priority: 9 --> 5
    • status: open --> open-postponed
     
  • Daniel Rupe

    Daniel Rupe - 2002-11-04

    Logged In: YES
    user_id=112680

    For now, it has been agreed to postpone this. In 2003, this can be revisited, probably as part of the re-architecture
    effort of PMT.

     
  • Daniel Rupe

    Daniel Rupe - 2002-12-04
    • assigned_to: rupe --> nobody
     

Log in to post a comment.

MongoDB Logo MongoDB