Info
This question is closed. Reopen it to edit or answer.
nominal array memory
2 views (last 30 days)
Show older comments
I am having memory issues when I convert large cellular arrays into nominal arrays. I am importing these cellular arrays of strings from outside data sources, so they are necessary at first. I then convert them into nominal arrays as there are only a few unique elements in each array. A simple example to illustrate the point would be:
x = cell(10^7,1);
for i = 1:length(x)
x{i} = 'H6';
end
y = nominal(x);
Initially, matlab is using .53 gigs, after x is created, it's .58 gigs. when y is created, my memory spikes to 2.2 gigs, then after nominal is finished running, matlab is still using 1.5 gigs. if I then type clear x, matlab is using only .632 gigs. This same memory problem happens if try x = nominal(x); instead. I am wondering if the garbage collector isn't deallocating memory properly, or if it is some other issue?
1 Comment
Answers (1)
Peter Perkins
on 24 Aug 2011
Mike, I believe this has something to do with the intelligence that's built into cell arrays under the covers to not store multiple copies of the same thing. You've created a somewhat artificial example where there's only one unique string in the cell array, and MATLAB takes advantage of that, at least initially. However, by the time you're done converting to nominal, some temporary copy of that cell array of strings apparently does have a separate copy of each cell's string. I suspect that by clearing x, you are getting back lots of memory not so much because x is cleared, but because the clear operation forces garbage collection.
1 Comment
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!