MATLAB: Am I unable to clear class definitions if one of the classes contains a property initialized to a class having an anonymous function as its property in MATLAB 7.11 (R2010b)

MATLAB

I have defined two classes as follows:
Class pClass
classdef pClass
properties
fun;
end
methods
function F = pClass(f)
F.fun = f;
end
end
end
Class qClass
classdef qClass
properties
opset={};
opinds=[];
end
methods
function M=qClass(opset)
opset={opset};
M.opset=opset;
M.opinds=[];
end
end
end
A function 'test' initializes these classes.
function test
fHandle=@(x) x;
P=pClass(fHandle);
Q=qClass(P);
end
When I execute the command
test,clear classes;
I receive the warning:
Warning: Objects of 'pClass' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'qClass' class exist. Cannot clear this class or any of its super-classes.
I cannot clear the class definitions unless I restart MATLAB.

Best Answer

This is a bug in MATLAB 7.11 (R2010b). The only workaround is to clear the object of the class, which contains the object with the anonymous function property, before it goes out of scope.
In the above example, the function 'test' should be defined as follows.
function test
fHandle=@(x) x;
P=pClass(fHandle);
Q=qClass(P);
clear Q;
end