Main Content

Reset Algorithm and Release Resources

Reset Algorithm State

When a user calls reset on a System object, the internal resetImpl method is called. In this example, pCount is an internal counter property of the Counter System object™. When a user calls reset, pCount resets to 0.

classdef Counter < matlab.System
% Counter System object that increments a counter

   properties (Access = private)
      pCount
   end
   
   methods (Access = protected)
      % Increment the counter and return 
      % its value as an output
      function c = stepImpl(obj)
          obj.pCount = obj.pCount + 1;
          c = obj.pCount;
      end

      % Reset the counter to zero.
      function resetImpl(obj)
         obj.pCount = 0;
      end
   end 
end

Release System Object Resources

When release is called on a System object, the internal releaseImpl method is called if step or setup was previously called (see Summary of Call Sequence). This example shows how to implement the method that releases resources allocated and used by the System object. These resources include allocated memory and files used for reading or writing.

This method allows you to clear the axes on the Whiteboard figure window while keeping the figure open.

   function releaseImpl(obj)
      cla(Whiteboard.getWhiteboard());
      hold on
   end

For a complete definition of the Whiteboard System object, see Create a Whiteboard System object.

See Also

|

Related Topics