Sunday, 15 August 2010

Matlab: Free memory of class objects -



Matlab: Free memory of class objects -

i wrote code using matlab's oop. in each class object save measurement info property , define methods evaluating them. average info set 1 single class object uses 32 mb of memory. writing gui should process these objects.

in first step load set of objects saved .mat-file (about 200 objects, 2gb on harddisk) , store them in handles struct. fill ram , utilize 6-7 gb, when loaded. no problem.

but if close gui, seems can't free used memory. tried different approaches no success.

setting info fields "empty" in destructor of class:

function delete(obj) obj.timevector = []; obj.valuevector = []; end

trying free in figure_closerequestfcn:

function figure_closerequestfcn(hobject, eventdata, handles) handles.data = []; handles = rmfield(handles,'data'); guidata(hobject,handles); clear handles; pack; %matlab issues warning, pack %be used command line, did %not work either delete(hobject); end

any ideas, besides closing matlab every time after working gui?

i found reply in matlab bug study center. seems exist since r2011b.

summary

storing objects in mat-files can cause memory leak , prevent object class beingness cleared

description

after storing instance of class, 'myclass', in mat-file, calling clear classes may result in warning:

warning: objects of 'myclass' class exist. cannot clear class or of superclasses.

this warning persists, if have cleared instances of class in workspace. warning may occur 1 mat-file format, , not another.

workaround

under circumstances, switching different mat-file format may eliminate warning.

http://www.mathworks.ch/support/bugreports/857319

edit: tried older formats saving, not work either. "error closing file" (http://www.mathworks.ch/matlabcentral/answers/18098-error-using-save-error-closing-file). matlab not back upwards saving class objects well. have live memory issues , restart matlab after every utilize of gui.

class matlab memory

No comments:

Post a Comment