As explained on the memory management page, xff stores the actual content of objects in a global variable, which means that the statement
clear obj;
does not have the desired effect of clearing (freeing) the memory associated with the variable (object) obj
. Instead, the memory must be freed using a class/object method (which in turn removes the object's content from the global variable).
AFT::ClearObject - remove object from global storage FORMAT: obj.ClearObject; No input / output fields. TYPES: ALL
% creating a temporary SDM sdm = xff('new:sdm'); % adding filters sdm.AddFilters(struct('number', 3, 'timepts', 120)); % getting filter regressors filterregs = sdm.SDMMatrix; % clearing object to free associated memory!! sdm.ClearObject;
While xff does support garbage collection, this does not affect objects that
bless
ed using the bless(obj);
or bless(obj, levels);
callAlso, the garbage collection is called only when a method on any given xff object is used; so it can sometimes take a while before memory becomes available again. In general, it is highly suggested that you clear objects once you know they are no longer required to free up the memory they allocate!