MATLAB: Class using static method causes clear warning

classclearoopstatic

I am implementing a class (ClassA) that use a static method for the initialization of a help variable, needed at Construction. An instance of ClassA is then a property of another class, ClassB. This seems to provoke the following MATLAB warning:
"Warning: Objects of 'ClassA' class exist. Cannot clear this class or any of its superclasses."
The reason I use the static help method is that ClassA in its turn has a property (Property1) that is an Array of object of a third class, ClassC. I cannot seem to instantiate a 1-by-n ClassC at Construction of ClassA, but must instead separately construct the 1-by-n ClassC and return it from the static function in the definition of Property1.
The same thing happens when I create the variable used to initialize ClassA.Property1 using a "normal" function implemented as a utility external to ClassA. Construction and execution of all of this runs fine. It's just that I have the habit of doing >> clear all; close all; clear classes; between executions to make sure that I get a fresh start including all the changes in each run.
When I delete all uses of static funcions or external helper functions, the problem dissappears.
In the MATLAB documentation there is some brief mentioning of this error, but I cannot find anything about it explicitly related to class Construction using static methods.

Best Answer

Hi Hakan,
instead of a static method you could use a constant property. BTW, what version of MATLAB do you use? I remember those problems with not being able to clear classes was in previous versions of MATLAB but far less often in more recent versions ...
Titus