【发布时间】:2011-11-06 09:21:58
【问题描述】:
假设我有一个班级myClass < handle。来自 Mathworks Help page on clear,
清除句柄图形句柄不会删除对象本身,删除对象也不会删除存储其句柄的变量。
hf = figure; % Creates figure object, stores handle in variable hf
delete(hf) % Removes figure object, but not the variable hf
clear hf % Removes hf from the workspace; figure could still exist
所以clear处理句柄对象不会从内存中删除它,除非我先明确地delete它..
我为myClass 指定了一个析构函数来进行适当的清理并删除对它的一些引用; clear 不会调用此析构函数。清除对象后是否可以调用该析构函数?
编辑:我应该提一下,虽然 delete 会自动调用 clear 如果没有对 myClass 对象的引用,我还有另一个类,比如 myOtherClass 具有引用 myClass 的属性,比如说myOtherClass.a。 myOtherClass 中还有其他属性不是myClass 的属性,但如果myOtherClass.a 也为空,则它们应该为空。让我知道如果这没有意义,那可能有点太罗嗦了。
【问题讨论】:
标签: matlab oop destructor matlab-class