How to delete explicitly

Hello all,

I am creating one box here and I want to delete that box explicitly.

How to do this ?

BRepPrimAPI_MakeBox* b1 = new BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 780, 90, 60);

TopoDS_Shape S1 = b1->Shape();

ais1 = new AIS_Shape(S1);

aContext->Display(ais1);

Can I call Delete() function on b1 to delete it ? Or Nullify() to S1 ?

Thanking u.

Gilles Debarbouille's picture

BRepPrimAPI_MakeBox is a CASCADE object manipulated by value. So you don't have to declare a pointer on it.

You just have to create the object as :

BRepPrimAPI_MakeBox b1(gp_Pnt(0, 0, 0), 780, 90, 60);

When you exit the scope of the variable b1, b1 is automatically destroyed except the shapes which are referenced by the context.

To know if an object is manipulated by Handle or not, you can visit the coresponding .cxx file and notice if the constructor returns a handle or not.

If the constructor returns a Handle, you have to do explicitly the new call. If not you just declare the variable with the corresponding arguments.

You can also know this information by the .cdl files. An object manupulated by Handles inherits of the root TShared.

For more information on the management of handled object you can read the answer done at the topic "how to delete a pointer to a Handle".

Douglas McCarthy's picture

Hello,

To add to what Gilles has already answered, you can also find these points in the Open CASCADE documentation.

Specifically: Foundation Classes User's Guide, ch. 2. Basics, section 2.1 Data types.

To summarize: when constructing an object, check to see whether the class inherits from MMgt_TShared. If it does, you have to create it using NEW. You can see inheritance in the doc if the class has been documented, or in the .cdl file if it has not.

Finally, because a handle is a smart pointer, you must not delete it; this is done automatically.

Best regards,

Douglas