Why need not to delete arc_curve in official example ?(C++/Rhino5)

Why need not to delete arc_curve in this example ?
Write like this,

         delete curve_object;
delete arc_curve 

Official example:

ON_3dPoint center(0.0, 0.0, 0.0);
double radius = 10.0;
    ON_Circle circle( center, radius );
    ON_ArcCurve* arc_curve = new ON_ArcCurve( circle );
    if( arc_curve )
      CRhinoCurveObject* curve_object = new CRhinoCurveObject();
      if( curve_object )
        // Set the curve to the curve object. Note,
        // curve_object will delete arc_curve.
        curve_object->SetCurve( arc_curve ); 
        if( context.m_doc.AddObject(curve_object) )
          delete curve_object;

curve_object owns the ‘lifetime’ of arc_curve after the call to SetCurve.

The key point is SetCurve(); therefore, arc_curve don’t be deleted.
BTW, If I delete arc_curve, some warning will happen ?

Yes, the key is SetCurve. If you delete the curve after calling SetCurve, then the curve_object instance will not know and Rhino will probably crash shortly after this due to memory corruption.

Thanks a lot.

Here are the comments for CRhinoCurveObject::SetCurve, found in rhinoSdkCurveObject.h:

// Description:
//   Specify the curve geometry.
// Parameters:
//   pCurve - [in] ~CRhinoCurveObject() will delete this curve
void SetCurve( ON_Curve* pCurve );

Notice that you are passing a non-const curve pointer.

Does this help?

:joy: thank you.
I got it.