[snip] > > Instead of closing your figures within the loop, try to clf the current figure and reuse the same figure window. This would also be better for performance. Even better, reuse all the internal handles as well (annotations, axes) such that instead of clf you would simply modify their internal properties - this would run much faster and would also remove the leak. > > I suspect that the current memory leak that you see may be due to the fact that Matlab does not properly destroy the figures' resources upon closing, and 20KB per iteration (=per figure) seems about right. > > Yair Altman > http://UndocumentedMatlab.com >
Thank you for the feedback. The example provided is for sure not the most optimal solution - I just tried to keep things simple.
Your idea regarding reusing the internal handles is good and I will definitely consider it. The downside is that we have thousands of lines of Matlab code that would need to be reworked. The task is furthermore complicated by the fact that figures are annotated based on the data so the number of annotations pr figure is not constant. Hmm...
I guess that our scenario (MCR exe running 24-7) is a bit special use case, but even small leaks "pr figure" will add up over time and eventually crash our MCR