title: Matlab: Free memory of class objects
body: <p>I recently wrote some code using Matlab's OOP. In each class object I save some measurement data as a property and define the methods for evaluating them. With an average data set one single class object uses about 32 MB of memory.
  Now I am writing a GUI that should process these objects. </p>
  
  <p>In the first step I load a set of objects from a saved .mat-file (about 200 objects, 2GB on harddisk) and store them in the handles struct. They fill the RAM and use about 6-7 GB, when loaded. This is no problem.</p>
  
  <p>But if I close the GUI, it seems that I can't free the used memory.
  I tried different approaches with no success.</p>
  
  <p>Setting the data fields to "empty" in the destructor of the class:</p>
  
  <pre><code>function delete(obj)
      obj.timeVector = [];
      obj.valueVector = [];
  end
  </code></pre>
  
  <p>Trying to free it in the figure_CloseRequestFcn:</p>
  
  <pre><code>function figure_CloseRequestFcn(hObject, eventdata, handles)
      handles.data = [];
      handles = rmfield(handles,'data');
      guidata(hObject,handles);
      clear handles;
      pack; %Matlab issues a warning, that pack could only 
            %be used from the command line, but that did
            %not work either
      delete(hObject);
  end
  </code></pre>
  
  <p>Any ideas, besides closing Matlab every time after working with the GUI?</p>