# System Functions

REF( ) | Control Reference Count

## Format

REF({ADD|DROP|READ} obj_id)

Where:

ADD | Keyword indicating an increment of the reference count for obj_id.
DROP | Keyword indicating an decrement of the reference count for obj_id.
obj_id | Object identifier (number/handle) of the object being referenced.
READ | Keyword indicating no change to the reference count for obj_id.

## Returns

Current reference count value (0 if the object is deleted).

## Description

The REF( ) function is used in Object-Oriented Programming to control access to an object by incrementing or decrementing the reference count. The DROP OBJECT directive can also be used to destroy an object.

The system sets the reference count for any newly created object to 1. If you plan to use an object more than once, use REF(ADD obj_id) to increment the reference count. When finished with an object, use REF(DROP obj_id) to decrement the reference count. When the reference count becomes zero, the object is deleted.

Only objects whose reference count is 1 can be deleted. Once an object is destroyed, its identifier may be reassigned to another object. You should no longer use the object identifier in your application, as it may reference a totally different object (if the identifier is reassigned).

All objects are destroyed when the application issues a START directive or if the END directive is entered at Command mode.

REF(READ obj_id) returns the current reference count value. All calls to REF( ) return the current reference count (or 0, if deleted).

## See Also

Object-Oriented Programming
DEF CLASS Define Object Class
PROPERTY Declare Object Properties
LOAD CLASS Pre-Load Class Definition
DROP CLASS Delete Class Definition
LOCAL Designation of Local Data
FUNCTION Declare Object Method
LIKE Inherit Properties
PROGRAM Create or Assign Program File
RENAME CLASS Change Name of Class
STATIC Add Local Properties at Runtime
DROP OBJECT Delete Object
NEW( ) Create New Object