More oop weirdness - Cannot clear class
Show older comments
R2013a doesn't display this problem.
.
Original question:
The issue, oop weirdness, reported by Matt J in the Newsgroup a couple of years ago seems to be fixed. It's good news that I fail to reproduce it with R2012a.
Now, I think I found a new testcase for The Mathworks testsuite. It is similar to the case reported by Jim Hokanson in Unable to clear classes. (Comment: Jim Hokanson on 27 Nov 2012 at 18:14)
First, restart Matlab (R2012a), then run the following commands and it is time to restart Matlab again.
>> c3m = C3Main( 1 );
>> clear all, clear classes
>> c3m = C3Main( 4 );
>> clear all, clear classes
Warning: Objects of 'C3Main' class exist. Cannot ...
Warning: Objects of 'C3Sub' class exist. Cannot ...
where
classdef C3Main < C3SuperC & C3SuperW
methods
function this = C3Main( N )
if nargin == 0, return, end
c3s = C3Sub( N );
this.addChild( c3s )
end
end
end
classdef C3Sub < handle
properties
Name = 'C3Sub';
val
Parent
end
methods
function this = C3Sub( N )
if nargin == 0, return, end
this( 1, N ) = C3Sub();
for ii = 1 : N
this( 1, ii ).val = 17 * ii;
end
end
end
end
classdef C3SuperC < handle
properties
Children = cell(0);
end
methods
function addChild( this, varargin )
for ca = varargin
child_array = ca{:};
for chld = child_array
this.Children = cat( 2, this.Children, {chld} );
chld.Parent = this;
end
end
end
end
end
and
classdef C3SuperW < hgsetget
properties
Name = 'C3SuperW';
end
end
.
The lines
this( 1, N ) = C3Sub();
for ii = 1 : N
this( 1, ii ).val = 17 * ii;
end
in the class C3Sub seems to be the problem - when N = 4. "This only occurs when there are more than 2 children." (Jim Hokanson). Indeed
>> crm = C3Main( 2 );
>> clear all, clear classes
>> crm = C3Main( 3 );
>> clear all, clear classes
Warning: Objects of 'C3Main' class exist. Cannot clear this ...
Warning: Objects of 'C3Sub' class exist. Cannot clear this class ...
Answers (1)
per isakson
on 19 Dec 2012
Edited: per isakson
on 19 Dec 2012
2 Comments
Matt J
on 19 Dec 2012
function c3handle_lost()
c3m = C3Main( 4 );
clear c3m
end
or
function c3handle_lost()
c3m = C3Main( 4 );
c3cleanup;
end
per isakson
on 21 Dec 2012
Edited: per isakson
on 22 Dec 2012
Categories
Find more on Handle Classes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!