Performing some final housekeeping

When your application has finished processing pipelines, you need to make sure it takes care of a few cleanup chores. These chores basically involve releasing the resources you obtained at the beginning to support pipeline execution.

NoteGarbage collection You should avoid using the DESTROY statement to clean up resources unless you are sure that the objects you are destroying are not used elsewhere. PowerBuilder’s garbage collection mechanism automatically removes unreferenced objects. For more information, see “Garbage collection and memory management”.

StepsTo clean up when you have finished using pipelines:

  1. Destroy the instance that you created of your supporting user object.

    To do this, code the DESTROY statement in an appropriate script and specify the name of the variable that contains that user-object instance.

  2. Disconnect from the pipeline’s source and destination databases.

    To do this, code two DISCONNECT statements in an appropriate script. In one, specify the name of the variable that contains your source transaction-object instance. In the other, specify the name of the variable that contains your destination transaction-object instance.

    Then test the result of each DISCONNECT statement.

  3. Destroy your source transaction-object instance and your destination transaction-object instance.

    To do this, code two DESTROY statements in an appropriate script. In one, specify the name of the variable that contains your source transaction-object instance. In the other, specify the name of the variable that contains your destination transaction-object instance.

For more information on coding the DESTROY and DISCONNECT statements, see the PowerScript Reference.

Example

The following code in the Close event of the w_sales_extract window takes care of these cleanup chores.

Destroying the user-object instance At the beginning of the Close event script, code the following statement to destroy the instance of the user object u_sales_pipe_logistics (which is stored in the iuo_pipe_logistics variable):

DESTROY iuo_pipe_logistics

Disconnecting from the source database Next, code these statements to disconnect from the source database, test the result of the disconnection, and destroy the source transaction-object instance (which is stored in the itrans_source variable):

DISCONNECT USING itrans_source;

   // Check result of DISCONNECT statement.
IF itrans_source.SQLCode = -1 THEN
   Beep (1)
   MessageBox("Database Connection Error", &
   "Problem when disconnecting from the source " &
   + "database. Please call technical support. " &
   + "~n~r~n~rDetails follow: " + & 
   String(itrans_source.SQLDBCode) + " " + & 
   itrans_source.SQLErrText, Exclamation!)
END IF

DESTROY itrans_source

Disconnecting from the destination database Finally, code these statements to disconnect from the destination database, test the result of the disconnection, and destroy their destination transaction-object instance (which is stored in the itrans_destination variable):

DISCONNECT USING itrans_destination;

   // Check result of DISCONNECT statement.
IF itrans_destination.SQLCode = -1 THEN
   Beep (1)
   MessageBox("Database Connection Error", & 
   "Problem when disconnecting from " + & 
   "the destination (Sales) database. " + & 
   "Please call technical support." + & 
   "~n~r~n~rDetails follow: " + & 
   String(itrans_destination.SQLDBCode) + " " + &
      itrans_destination.SQLErrText, Exclamation!)
END IF

DESTROY itrans_destination