Skip to content

onCleanup

miscellaneous · scripts/miscellaneous/onCleanup.m

onCleanup - run a cleanup function when the object is destroyed.

  cleanupObj = onCleanup()
  cleanupObj = onCleanup(cleanupFun)

Clean-room MATLAB R2026a-compatible handle class (nexus#1660, nexus#1834).
Behaviour matched against MATLAB R2026a documented API and live probes;
this file is not a copy of MathWorks sources.

Multiple instances (nexus#1834): each object's task runs when that object
is destroyed. On function exit (including error and return inside try/catch)
R2026a runs tasks in creation order. Explicit clear runs in listed-name
order. The task runs exactly once (last handle reference).