memory lost (allocated) by uigetfile

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 Kommentare

Friedrich
Friedrich am 6 Sep. 2012
Bearbeitet: Friedrich am 6 Sep. 2012
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
Jan am 6 Sep. 2012
@friedrich: No, pre-allocation is only useful, if the allocated memory block is used later.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jan
Jan am 6 Sep. 2012
Bearbeitet: Jan am 6 Sep. 2012

1 Stimme

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
Robin am 7 Sep. 2012

0 Stimmen

Thanks for your answer. I really need the matrix to be in 1 object since i need to do some 3D connected component analysis for segmentation. I know that the free memory is fragmented.
@ friedrich : i don't even load the image. By even cancelling the UI, by just pressing cancel at selecting a file the memory is substantially fragmented.
So is there any way to prevent that uigetfile ( i only need path-file name ) fragments the memory so badly?

2 Kommentare

Jan
Jan am 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
Walter Roberson am 7 Sep. 2012
And switch to the 64 bit version of MATLAB.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Sep. 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by