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 个评论

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(...)
@friedrich: No, pre-allocation is only useful, if the allocated memory block is used later.

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2012-9-6
编辑:Jan 2012-9-6

1 个投票

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 2012-9-7

0 个投票

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 个评论

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.
And switch to the 64 bit version of MATLAB.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

提问:

2012-9-6

Community Treasure Hunt

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

Start Hunting!

Translated by