memory lost (allocated) by uigetfile
Show older comments
Dear matlab users, I work on large CT images 512x512x234, so i need a lot of memory. However, when i want the use to be able to select a file i lose a lot of allocated memory. when i restart matlab :
>>memory Maximum possible array: 1239 MB (1.299e+009 bytes) *
Then by ONLYusing the command [file path]=uigetfile({'*.img'},'Get .img file'); i lose the memory (not even loading the image):
>> memory Maximum possible array: 987 MB (1.035e+009 bytes) *
I really need the UI to have the user select a file instead of copy pasting the path and filename. Does anybody have an idea how to solve this? or another whay to selec t the file/path name? (Pack doesn't work)
Thanks!
edit: sometimes i even lose 400 MB without even selecting a file (cancel the UI). By the way, i'm working with Matlab 7.10.0 (R2010a)
2 Comments
Maybe allocate the memory for the image first and then call uigetfile. So something like
tmp = zeros(512,512,234) %maybe allocate it as uint8 directly
uigetfile(...)
Jan
on 6 Sep 2012
@friedrich: No, pre-allocation is only useful, if the allocated memory block is used later.
Answers (2)
The command uigetfile does not leak memory. But the free memory is fragmented. To store a large array (of en elemtary type like DOUBLE or UINT8), the the memory must be available as an contiguous block. If you have 1 GB before calling a function, and one single scalar is created and stored exactly in the center of the free block, only 0.5 GB can be used for storing a large array afterwards, although 1.0GB - about 100 Bytes are free.
Therefore your 512x512x234 images could be stored more efficiently as {1 x 234} cell of [512 x 512] matrices.
Robin
on 7 Sep 2012
0 votes
2 Comments
Jan
on 7 Sep 2012
Please post comments as comments, not in the answer section.
No, you cannot influence the memory manager reliably. There have been some startup parameters, which enable different strategies for the memory management, and you can clear the Java heap. The most efficient workaround would be to install more RAM.
Walter Roberson
on 7 Sep 2012
And switch to the 64 bit version of MATLAB.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!