Search Mailing List Archives

Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[farmshare-discuss] Matlab imread memory leak while reading JPEG2000 images

Pierre Martineau pierrem at
Tue Jul 24 17:22:17 PDT 2012

It looks like there is a memory leak in the Matlab imread function when reading lossless JPEG2000 files; the problem is easily reproduced by running the test program below on corn with the current Matlab version (Release 2011b).  The loop shows the virtual memory growing; kept unbound, Matlab ends up crashing.  Clearing the memory at each iteration using any flavor of "clear" has no effect.  I believe this problem may be related to an alleged Sun JAI bug reported at


%grab pid of current MATLAB process to monitor memory consumption
[~, matlabPid] = unix('pidof MATLAB | grep .$');
matlabPid = strtrim(matlabPid);

%create large (45M) jpeg2000 file
img = uint8(rand(5000, 3000, 3)*225);
tmpName = [tempname '.jp2'];
imwrite(img, tmpName, 'Mode', 'lossless');
imgInfo = imfinfo(tmpName);

%iterate reading the same file and monitor virtual memory size
jp2 = imformats('jp2');
for i=1:100
    feval(, tmpName);
    [~, VmData] = unix(['grep VmData: /proc/' matlabPid '/status | awk ' char(39) '{print $2}' char(39)]);

%clean up

More information about the farmshare-discuss mailing list