Class Thread attribute is not calling .Constructor() and .Deconstructor()

Got a Class with the Thread attribute, C6 & C11 help docs state

THREAD Specify memory for all class variables are allocated once for each execution thread. Also causes Constructors and Destructors to be called on thread start and exit.

I’ve added some code which primes some property variables, but these are not being primed.

I am assuming the names for the Constructors and Deconstructors are:

The help doc refers to them as plurals, but there is no other mention of what their name should be!

So apart from specifically calling the constructor & deconstructor methods, how do I get the Thread attribute to call these methods or why doesnt the compiler highlight why these methods are missing if these are the wrong names to use?

Either way I can not get the Thread attribute to automatically what ever the two methods should be called.


The help[CLASS (object definition)]
shows the correct method names are CONSTRUCT and DESTRUCT

From the help: (bold added by me)

A CLASS method labelled “Destruct” is a destructor method which is automatically invoked when the object leaves scope, immediately before the data members of the object are de-allocated. The “Destruct” method may not receive any parameters. You may explicitly call the “Destruct” method in addition to its automatic invocation.

Back to my words…

Additionally I can assure you that they are called when the object is instantiated or disposed (or auto disposed as the object leaves scope)

Additonally a class object declared with a ,THREAD attribute does instantiate as a new thread starts, and is auto disposed when the thread ends.


Those work, but not Classname.Constructor and Classname.Destructor.


Edit. I’ve found that section of the help docs as well.


I must be suffering from dementia (the stress of being done over by criminals who are the state - never thought I’d get radicalised living in this tiny village but I understand why massacres occur now, they are a community’s dirty little secret) because I’ve even added that to my class writing template which I’m not using in this instance!

#Display('Properties (variables) allocated once for')
#Display('each execution thread.')
#Display('Methods automatically added by this template:')
#Display('        ' & %iscwClassName & '.Construct')
#Display('        ' & %iscwClassName & '.Destruct')
#Display('Constructors && Destructors called automatically on thread')
#Display('Class start and exit.')

Additionally, I suggest you always define the Destruct as PROCEDURE,VIRTUAL in the base class, then as DERIVED in the extending classes. This is critically important when using certain design patterns, like Factory patterns that are using the base class. Without VIRTUAL attribute, the factory will not call the extended class’ destructor, but rather only the one for the base class.

If you didn’t write the base class, then you won’t have this option (unless you add it manually).

1 Like

I’ll remember to put that option in my template here.