PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Low references and strong references
  • Example of references
  • Strong reference
  • Low reference
  • Forced destructor
  • Equivalence
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Advanced management of class instances
Overview
The advanced management of instances is used to choose the mode for taking reference. This choice directly impacts the freeing of the class objects: depending on the selected take of reference, the "Destructor" will not be called at the same time.
Two modes are available for taking reference:
  • the low reference.
  • the strong reference.
Reminder: Taking reference is used to reference the same data area as the source element. For example, two variables point to the same class object. To take reference on an object, all you have to do is use the <- operator.
Important: In any case, the call to the destructor can be forded by the "Delete" keyword.
Versions 17 and later
AndroidUniversal Windows 10 AppJava The management of strong references is now available.
AndroidJava The management of low references is now available.
New in version 17
AndroidUniversal Windows 10 AppJava The management of strong references is now available.
AndroidJava The management of low references is now available.
AndroidUniversal Windows 10 AppJava The management of strong references is now available.
AndroidJava The management of low references is now available.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Low references and strong references
Two types are available for taking reference:
  • The strong reference (by default): In this case, the class object will be freed only when all the object references are freed.
  • The low reference: In this case, the objects will be automatically freed according to their scope (even if a global reference was taken on these objects). The low reference must be specified during the dynamic instantiation of the object taking reference.
    Universal Windows 10 App The management of low references is not available.
To specify a low reference, use the following syntax:
Reference is dynamic object Class1, weak
or:
Reference is dynamic object Class1 <weak>
Note: The following syntax is used to force the take of low reference for all the objects:
ExecutionMode(ForceDestructorNonDynamicObject)
Caution: This operating mode is global to the entire application and it may interfere with the operating mode of the components.
Example of references

Strong reference

At the end of the procedure, the "MyObject" object is not freed (the destructor is not called). The "MyObject" object will be freed when "GlobalReference" is freed. Therefore, "MyObject" will be freed when the window is closed.
// Global declarations of the window: dynamic instantiation of Class1 object
GlobalReference is dynamic object Class1
// Local procedure of the window
PROCEDURE LocalWindowProcedure()

// Instantiate a Class1 object
MyObject is object Class1

// Taking strong reference on the MyObject object.
GlobalReference <- MyObject

Low reference

At the end of the procedure, the "MyObject" object is freed (the destructor is called) and "GlobalReference" is set to NULL.
// Global declarations of the window: dynamic instantiation of Class1 object
GlobalReference is dynamic object Class1, weak
// Local procedure of the window
PROCEDURE LocalWindowProcedure()

// Instantiate a Class1 object
MyObject is object Class1

// Taking low reference on the MyObject object.
GlobalReference <- MyObject
Forced destructor
You have the ability to force the call to the destructor (free the object) even if a strong reference was taken on this object.
The following syntax is used to force the call to the destructor:
// The destructor will be called at the end of variable scope
// (even if a strong reference was taken on this object)
MyObject is object Class1, force Destructor
or:
// The destructor will be called at the end of variable scope
// (even if a strong reference was taken on this object)
MyObject is object Class1 <force Destructor>

Universal Windows 10 App This feature is not available.

Equivalence

the following codes (example 1 and example 2) are equivalent. In both cases, the object will be freed at the end of the procedure.
Example 1:
// Global declarations of the window
// Dynamic instantiation of a Class1 object
GlobalReference is dynamic object Class1, weak
// Local procedure of the window
PROCEDURE LocalWindowProcedure()

// Instantiate a Class1 object
MyObject is object Class1

// Taking low reference on the MyObject object.
GlobalReference <- MyObject
Example 2:
// Global declarations of the window
// Dynamic instantiation of a Class1 object
GlobalReference is dynamic object Class1
// Local procedure of the window
PROCEDURE LocalWindowProcedure()

// Instantiate a Class1 object
MyObject is object Class1, force Destructor

// Taking low reference on the MyObject object.
GlobalReference <- MyObject
Minimum required version
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment