Release System Object Resources

This example shows how to release resources allocated and used by the System object™. These resources include allocated memory, files used for reading or writing, etc.

Release Memory by Clearing the Object

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

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

Complete Class Definition File with Released Resources

classdef Whiteboard < matlab.System
% Whiteboard Draw lines on a figure window
%
% This System object shows the use of StringSets
%
   properties
     Color = 'blue'
   end

   properties (Hidden)
     % Let user choose a color
     ColorSet = matlab.system.StringSet({'red','blue','green'});
   end

   methods (Access = protected)
     function stepImpl(obj)
         h = Whiteboard.getWhiteboard();
         plot(h, ...
           randn([2,1]), randn([2,1]), ...
           'Color',obj.Color(1));
     end

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

   methods (Static)
     function a = getWhiteboard()
         h = findobj('tag','whiteboard');
         if isempty(h)
           h = figure('tag','whiteboard');
           hold on
         end
         a = gca;
     end
   end
end

Related Examples

Was this topic helpful?