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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by