Thread Subject:
Memory leak in file DELETE in R2010b?

Subject: Memory leak in file DELETE in R2010b?

From: Kevin

Date: 1 Apr, 2011 21:34:05

Message: 1 of 4

Hi everyone,

Can someone kindly try out the following Matlab codes? I am not sure if I have found out a memory leak in using DELETE to simply delete a file.

I bracketed the DELETE command with the MEMORY command so that I can see the memory usage before and after calling DELETE.

Look at the line "Maximum possible array: ....". This number is constant at the beginning but before we hit 100 iterations, this number will decrease.

This took me 3 hours to find out. Am I missing something?

Kevin

--------------------------------------------------------------------------------

%% Create file1.mat in current directory.
file1 = 'file1.mat';
save(file1);

for n = 1:100
    
    %% Create file2.mat.
    file2 = 'file2.mat';
    copyfile(file1, file2);

    %% Delete file2.mat.
    if exist(file2, 'file') ~= 0
        memory
        delete(file2);
        memory
        fprintf('--------------------------------------------\n\n');
    end
    if exist(file2, 'file') ~= 0
        error('Cannot delete file2.mat.');
    end

end

Subject: Memory leak in file DELETE in R2010b?

From: Kevin

Date: 1 Apr, 2011 21:52:05

Message: 2 of 4

I think the solution is to use DOS to do the delete:

dos('del file2.mat');

This will be the workaround.

Is Java being the problem here?

Subject: Memory leak in file DELETE in R2010b?

From: Byron

Date: 19 Aug, 2012 23:48:06

Message: 3 of 4

"Kevin" wrote in message <in5he5$641$1@fred.mathworks.com>...
> I think the solution is to use DOS to do the delete:
>
> dos('del file2.mat');
>
> This will be the workaround.
>
> Is Java being the problem here?


I was reading in a few hundred thousand binary files from a frame grabber and deleting them on the fly with delete(‘path\fname’). at around 760k files i got java heap space, out of memory error.
 I solved the problem by switching to java.io.File(‘path\fname’).delete(), which maintains same speed but no memory leak issues. I tried system(‘del path\fname’) but it was 20x slower.

Just though i’d share incase anyone else needed a faster workaround than the system cmd.

Subject: Memory leak in file DELETE in R2010b?

From: Kevin

Date: 4 Sep, 2012 19:43:08

Message: 4 of 4

Hi Byron,

Thank you very much for posting your work-around to this thread. I know nothing about Java and so I will never be able to find this work-around.

I am just wondering why Mathworks have not fixed this problem.

Kevin


"Byron" wrote in message <k0rtvm$6kc$1@newscl01ah.mathworks.com>...
> "Kevin" wrote in message <in5he5$641$1@fred.mathworks.com>...
> > I think the solution is to use DOS to do the delete:
> >
> > dos('del file2.mat');
> >
> > This will be the workaround.
> >
> > Is Java being the problem here?
>
>
> I was reading in a few hundred thousand binary files from a frame grabber and deleting them on the fly with delete(‘path\fname’). at around 760k files i got java heap space, out of memory error.
> I solved the problem by switching to java.io.File(‘path\fname’).delete(), which maintains same speed but no memory leak issues. I tried system(‘del path\fname’) but it was 20x slower.
>
> Just though i’d share incase anyone else needed a faster workaround than the system cmd.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matlab Byron 19 Aug, 2012 19:49:12
delete Byron 19 Aug, 2012 19:49:12
memory leak Byron 19 Aug, 2012 19:49:12
rssFeed for this Thread

Contact us