What happens to cleared custom `handle` objects?
1 回表示 (過去 30 日間)
古いコメントを表示
I know that MATLAB exposes the handle class which alllows one to define passed-by-reference objects like:
classdef ConcreteHandle < handle
properties
UserData = []
end
methods
function self = ConcreteHandle(data)
arguments
data = []
end
self.UserData = data;
end
end
end
How does the behaviour of this class differ from the existing graphical handle objects? For example:
fh = figure;
clear fh
Doesn't delete the figure (but close(fh) or delete(fh) will). Even after the reference to fh is cleared you can still recover it with built-in utilities like findall():
fh = findall(0, 'Type', 'Figure');
What happens if I construct an instance of my custom class:
c = ConcreteHandle();
clear c
Is c (and the data in c.UserData) handed over to the gargabe collector? Does there exist an equivilant call to findall() or a similar utility that lets me find c?
0 件のコメント
採用された回答
Matt J
2024 年 5 月 20 日
編集済み: Matt J
2024 年 5 月 20 日
If you clear c, then that copy of the handle is gone, while other shared instances of it that you may have created remain. If you clear() every last shared instance that you've created, then the handle object is irretrievably gone.
The same is true of graphics handles. The reason findall can recover a handle to an open figure is because there is no way to clear() every shared instance of a handle to an open figure. This is because groot stores a shared instance of the handle in its Children property, which remains there until the figure is closed or deleted.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!