<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: File deletion memory leaks, performance	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=file-deletion-memory-leaks-performance</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 08 Sep 2022 19:50:45 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: SKM		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-514979</link>

		<dc:creator><![CDATA[SKM]]></dc:creator>
		<pubDate>Thu, 08 Sep 2022 19:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-514979</guid>

					<description><![CDATA[It is 10 years since the original article, but I would like to bring to attention that such issues have not yet been resolved. For example, programmatically opening and closing files in the Matlab editor results in a memory leak. The following code illustrates the problem:
 
&lt;pre lang=&quot;Matlab&quot;&gt;
function TestEditorMemoryLeak(filepaths)
    for i = 1 : numel(filepaths)
        docobj = matlab.desktop.editor.openDocument(filepaths{i});
        disp([num2str(i), &#039;: &#039;, filepaths{i}]);
        pause(0.2);
        docobj.closeNoPrompt();
    end
end
&lt;/pre&gt;

Warning: do not run the above code with a large number of files. Depending on how much Java heap memory is allocated under matlab general settings, it could cause matlab to crash and hang causing loss of command history and matlab settings.

I used the above code on about 1300 files, where each file was not too large - maybe an average of around 50 lines per file. On my system, which has the default 768 MB of Java heap memory allocated, the memory runs out after about a thousand files and matlab (2020a) hangs, badly.

I thought that Java garbage collection might clean up after the function runs, but the 768 MB of memory remains used and never goes back to normal in the Windows task manager.
 
Increasing the Java heap memory setting appropriately, resolves the issue, but I would like to find a real solution.]]></description>
			<content:encoded><![CDATA[<p>It is 10 years since the original article, but I would like to bring to attention that such issues have not yet been resolved. For example, programmatically opening and closing files in the Matlab editor results in a memory leak. The following code illustrates the problem:</p>
<pre lang="Matlab">
function TestEditorMemoryLeak(filepaths)
    for i = 1 : numel(filepaths)
        docobj = matlab.desktop.editor.openDocument(filepaths{i});
        disp([num2str(i), ': ', filepaths{i}]);
        pause(0.2);
        docobj.closeNoPrompt();
    end
end
</pre>
<p>Warning: do not run the above code with a large number of files. Depending on how much Java heap memory is allocated under matlab general settings, it could cause matlab to crash and hang causing loss of command history and matlab settings.</p>
<p>I used the above code on about 1300 files, where each file was not too large &#8211; maybe an average of around 50 lines per file. On my system, which has the default 768 MB of Java heap memory allocated, the memory runs out after about a thousand files and matlab (2020a) hangs, badly.</p>
<p>I thought that Java garbage collection might clean up after the function runs, but the 768 MB of memory remains used and never goes back to normal in the Windows task manager.</p>
<p>Increasing the Java heap memory setting appropriately, resolves the issue, but I would like to find a real solution.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-351386</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 16 Jun 2015 11:42:47 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-351386</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-351380&quot;&gt;stefan&lt;/a&gt;.

@Stefan - MAT files do not contain history (except if you designed them to contain it), so yyour only option is to check if this file was backed up.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-351380">stefan</a>.</p>
<p>@Stefan &#8211; MAT files do not contain history (except if you designed them to contain it), so yyour only option is to check if this file was backed up.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: stefan		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-351380</link>

		<dc:creator><![CDATA[stefan]]></dc:creator>
		<pubDate>Tue, 16 Jun 2015 09:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-351380</guid>

					<description><![CDATA[i ve got a problem with saving matlab files (.mat). yesterday I overwrote my existing file. no errors occured. today, my file is almost empty (one of 4 folders left).
is there ANY possibility to recover/restore?]]></description>
			<content:encoded><![CDATA[<p>i ve got a problem with saving matlab files (.mat). yesterday I overwrote my existing file. no errors occured. today, my file is almost empty (one of 4 folders left).<br />
is there ANY possibility to recover/restore?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-348182</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 18 Apr 2015 17:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-348182</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-348142&quot;&gt;YoGabbaGabba&lt;/a&gt;.

@Bobby - the test script above should be fairly easy for you to run on your specific system to check this. And as noted, you can always use the &lt;code&gt;java.io.File(tn).delete()&lt;/code&gt; workaround.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-348142">YoGabbaGabba</a>.</p>
<p>@Bobby &#8211; the test script above should be fairly easy for you to run on your specific system to check this. And as noted, you can always use the <code>java.io.File(tn).delete()</code> workaround.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: YoGabbaGabba		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-348142</link>

		<dc:creator><![CDATA[YoGabbaGabba]]></dc:creator>
		<pubDate>Fri, 17 Apr 2015 20:40:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-348142</guid>

					<description><![CDATA[Do we know if this memory leak still exists in Matlab 2013b or newer versions?

If so, if I want to override these files for a project, how do I avoid shadow warnings if I wish to keep the files named the same and on my path? Thanks]]></description>
			<content:encoded><![CDATA[<p>Do we know if this memory leak still exists in Matlab 2013b or newer versions?</p>
<p>If so, if I want to override these files for a project, how do I avoid shadow warnings if I wish to keep the files named the same and on my path? Thanks</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jeremy		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-208628</link>

		<dc:creator><![CDATA[Jeremy]]></dc:creator>
		<pubDate>Mon, 03 Jun 2013 21:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-208628</guid>

					<description><![CDATA[Yair- Dug up this post while investigating a similar issue with:
&lt;pre&gt;exist(name,&#039;file&#039;)&lt;/pre&gt;
In the Matlab call of exist, they are caching the result as to make subsequent calls fast, but if you do large numbers of &quot;exist&quot; calls on files with different names (e.g. with constantly increasing index values in the file name), each one of those results is permanently cached. The result is a constant memory &quot;leak&quot; (well, technically memory is being put to good use, so not a leak in that sense, but there apparently no way to clear that cache and recover the memory). However, using:
&lt;pre&gt;file.io.File(name).isFile&lt;/pre&gt;
works like a charm... AS LONG AS you don&#039;t have the need to search the entire Matlab path. That is the ONE thing the Java call won&#039;t do that the exist() call does.]]></description>
			<content:encoded><![CDATA[<p>Yair- Dug up this post while investigating a similar issue with:</p>
<pre>exist(name,'file')</pre>
<p>In the Matlab call of exist, they are caching the result as to make subsequent calls fast, but if you do large numbers of &#8220;exist&#8221; calls on files with different names (e.g. with constantly increasing index values in the file name), each one of those results is permanently cached. The result is a constant memory &#8220;leak&#8221; (well, technically memory is being put to good use, so not a leak in that sense, but there apparently no way to clear that cache and recover the memory). However, using:</p>
<pre>file.io.File(name).isFile</pre>
<p>works like a charm&#8230; AS LONG AS you don&#8217;t have the need to search the entire Matlab path. That is the ONE thing the Java call won&#8217;t do that the exist() call does.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-107871</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 07 Sep 2012 12:33:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-107871</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-107841&quot;&gt;Jan Simon&lt;/a&gt;.

@Jan - thanks, sharp eyes! (now corrected)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-107841">Jan Simon</a>.</p>
<p>@Jan &#8211; thanks, sharp eyes! (now corrected)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jan Simon		</title>
		<link>https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance#comment-107841</link>

		<dc:creator><![CDATA[Jan Simon]]></dc:creator>
		<pubDate>Fri, 07 Sep 2012 08:46:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3133#comment-107841</guid>

					<description><![CDATA[In text you explain &quot;*pause* takes 1.5-2 milliseconds to run while java.io.File only takes 0.4-0.5 ms&quot;. Do you really mean *pause* or *delete*?]]></description>
			<content:encoded><![CDATA[<p>In text you explain &#8220;*pause* takes 1.5-2 milliseconds to run while java.io.File only takes 0.4-0.5 ms&#8221;. Do you really mean *pause* or *delete*?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
