Destroy Objects in a Simulation

Having created or generated Objects in your simulation model, you can define Actions to destroy those objects at any point during the process. All simulation objects are destroyed automatically when the simulation completes.

You have two options for destroying the Objects in your simulation model:

Dynamically destroy the Objects through a DestroyObject Action element
Dynamically destroy the Objects using Javascript in an Action element
 

The result of the deletion can be observed in the change of local variables, on the Local window.

Destroy an Object through a DestroyObject Action

Step

Action

See also

1

On your Activity diagram, drag an Action icon from the Diagram Toolbox, and select the Other | DestroyObject context menu option to define it as a DestroyObject Action element.

 

Action

2

Set the classifier of the DestroyObject Action to the Class of which the Object is an instance.
(Advanced | Set Classifier).

Create an Action Pin on the DestroyObject Action, of kind input.

 

 

 
Action Pin

3

Connect the Input Action Pin to an Object Flow connector from the last Action that operated on the Object. In this example, the last Action that operated on the Object is the Action that created it.

 

DelObjEg

 

Object Flow

4

Perform a Simulation on the diagram. The process passes the Object name or value into the Input Action Pin as a parameter. When the DestroyObject Action is executed, it deletes the Object having that name or value from the model.

In the example, the instance of Class1 is specifically destroyed before Action4 is processed, but the results of Action2 are unaffected.

 

 

Destroy an Object using Javascript

On the Properties Effect page of the Action element, in the Effect field, type either:

sim.DestroyObject ("objectname")

 

or

delete sim.objectFullName

 

 

For example:

DeleteAction

 

Notes

In either case, you can also destroy a global object (one that is created outside the process flow) by identifying the Object to the Action performing the destruction; in the case of the DestroyObject Action, by passing the Object name from a Port on the Object to the Input Pin on the Action through an Object Flow connector

Learn more