WeakRef

From Real Software Documentation

Jump to: navigation, search
Class (inherits from Object)

Allows you to retain a reference to an object without requiring it to stay alive.



Properties
Value


Constructors

WeakRef.Constructor(obj as Object)



Notes

WeakRef is useful when you want to find out when an object (such as a database or TCP/IP connection) is still in use somewhere in the application. The reference returned by WeakRef goes to Nil as soon as there are no longer any references to the object. This is the signal that you can do any necessary cleanup work.

When the object is destroyed, the WeakRef's value will change to Nil after all ordinary references have been released and the object has been destroyed. Otherwise, the Value property returns the target object.


Examples

This example creates a weak reference to a REALSQLdatabase object. The property db as REALSQLdatabase is a property of the App class.

Dim DBRef as WeakRef

// Create Database Object
DB = New REALSQLdatabase
DBRef=New WeakRef(OrdersDB)
// Set Database File
OrdersDB.databaseFile = GetFolderItem("Orders.rsd")
Personal tools