Does Matlab support destructor function in class?

For a normal class (not a handle class), can we set a destructor function so that when deleting a class instance, it does some house keeping work itself?
For example, I have a class containing a timer. When I delete the class, the timer handle is deleted, but the timer is still there and may be running. I have to remember to delete the timer manually before deleting the class.
Is Matlab considering adding this in newer versions? Thanks!

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 10 月 31 日

0 投票

You will have to write your own delete() method for the class. Then when you delete the object, this method is called and it stops/deletes the timer.

3 件のコメント

Walter Roberson
Walter Roberson 2012 年 10 月 31 日
Would delete() be called automatically when an instance is cleaned up automatically such as it going out of scope?
Daniel Shub
Daniel Shub 2012 年 10 月 31 日
I don't think so. Value classes do not have a delete method.
Walter Roberson
Walter Roberson 2012 年 10 月 31 日
I should look again at how onCleanup() works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

製品

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by