Navigation:  Programming Cookbook > Database Connectivity >

Cleaning up

Previous pageReturn to chapter overviewNext page

Unreferenced Database Connection objects such as DBConnections and DBStatements are automatically cleaned up during garbage collection. This means that it is not explicitly necessary to close these objects in order to free up the external resources they are using. However, because this cleaning up process makes use of Smalltalk finalization, you cannot be sure exactly when the resources will be freed. In general, unless the finalization queue grows too large, the finalization process will only wake up every 10 seconds or so to perform its work. Consequently, you may have to wait up to this length of time (and in some cases longer) for the ODBC objects to be fully disposed of once all references to them have disappeared.

Here's an example you can use to demonstrate this if you are have Microsoft Access available:

rs := c query: 'select * from Orders'. "Evaluate it"

 

Now try to view the Orders table in design mode in Microsoft Access. You should get an error message indicating that the Orders table is in use by another application (i.e. a DBResultSet in Dolphin). Now move back to Dolphin and free up the result set:

rs := nil.

If you quickly go back to Access and try to open the design window again, you will probably find that the table is still locked. Now wait for 10-20 seconds and try once more. This time you should succeed. This indicates that once the reference to the DBResultSet was dropped, it still took some time for the external ODBC memory associated with it to be freed by Dolphin.