ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / OOP (Object Oriented Programming)
  • Overview
  • Low references and strong references
  • Example of references
  • Strong reference
  • Weak reference
  • Forced destructor
  • Equivalence
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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: Reference operators are used to reference the same data area as the source element. For example, two variables point to the same class object. To reference 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.
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, objects will be automatically deleted 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>
Remark: 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

Weak 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 version required
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 07/03/2023

Send a report | Local help