How to remove the data from a handle class from memory
25 views (last 30 days)
I feel like an idiot but I don't seem to be able to solve the following problem:
When I define a handle class, how do I destroy it?
classdef test_class < handle
% Lots of data
data = rand(1e4,1e4);
% What do I put here to destroy the object itself: erase the object itself from memory
% Only "clear all" seems to work
Testing this with
x = test_class;
shows that the class data is effectively destroyed by clear all.
Does anyone know what code to use in the delete function ??
Thanks for you replies
Ghada Saleh on 7 Aug 2015
I understand you want to clear the class definition in the 'delete' method. You can use the following command:
Note that this command issues a warning and does not clear a class of objects if any of those objects still exists after the workspace is cleared. For example, objects can still exist in persistent variables of functions or figure windows. Also, lear classes does not clear a class if its file is locked using the mlock command. No warning is issued in this case.
Also, if you are using MATLAB R2012b or earlier versions, note that there is a bug when using clear classes. This bug is fixed in R2013a.
I hope this helps,