<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>garbage collection manager Archives - Dragonsoft Technology View</title>
	<atom:link href="https://blog.dragonsoft.us/tag/garbage-collection-manager/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.dragonsoft.us/tag/garbage-collection-manager/</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Tue, 31 Mar 2009 15:14:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://blog.dragonsoft.us/wp-content/uploads/2022/04/logo-main-bw-150x150.png</url>
	<title>garbage collection manager Archives - Dragonsoft Technology View</title>
	<link>https://blog.dragonsoft.us/tag/garbage-collection-manager/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">2577970</site>	<item>
		<title>File locks or when garbage collection goes bad</title>
		<link>https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/</link>
					<comments>https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/#respond</comments>
		
		<dc:creator><![CDATA[Serguei Dosyukov]]></dc:creator>
		<pubDate>Mon, 02 Mar 2009 12:23:41 +0000</pubDate>
				<category><![CDATA[Fun stuff with C#]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[cannot delete file]]></category>
		<category><![CDATA[file lock]]></category>
		<category><![CDATA[garbage collection manager]]></category>
		<category><![CDATA[manage garbage collection process]]></category>
		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=842</guid>

					<description><![CDATA[<p>With introduction of garbage collection (System.GC name space) in .Net, life of the Windows programmer become easy &#8211; no need to worry about releasing objects, code become simpler, etc. In &#8220;old&#8221; time one would need to use Interfaces to achieve similar functionality and it does have some advantage even over GC &#8211;<a class="moretag" href="https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/"> Read more</a></p>
<p>The post <a href="https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/">File locks or when garbage collection goes bad</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>With introduction of <a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" target="_blank">garbage collection</a> (System.GC name space) in .Net, life of the Windows programmer become easy &#8211; no need to worry about releasing objects, code become simpler, etc.<br />
In &#8220;old&#8221; time one would need to use Interfaces to achieve similar functionality and it does have some advantage even over GC &#8211; immediate garbage collection or release of allocated resources/objects.</p>
<p>When writing code in .Net some of us take many things for granted and not always keep in mind that many operations are performed in the context of the unmanaged code or in the &#8220;old way&#8221;&#8230;</p>
<p>File operations or legacy code wrappers are perfect example.<br />
Just because library is available as managed code, it does not mean that everything has ability to &#8220;self-heal&#8221;.<br />
For example in code file is open for edit with lock being placed.<br />
If the file in not closed explicitly, it would be a responsibility of the owner process to release the lock at the time of releasing associated resources &#8211; when process is destroyed.</p>
<p>With garbage collection, just because we are no longer using/owning the process/object, it does not mean that it has been destroyed immediately after. GC management core will release object when it &#8220;feels&#8221; fit, therefore introducing latency into the process.</p>
<p>Off course, proper way would be to be more careful within the code and make sure any locks are released in managed and predictable way: Open/Close, Lock/Unlock, &#8230; Easy solution, but not always accessible, especially when working with 3rd party libraries.</p>
<p>So instead, we can force GC manager to &#8220;collect garbage&#8221; in-place with the following small code:</p>
<pre class="brush: csharp; title: ; notranslate">// See code follow up below
System.GC.Collect();
System.GC.WaitForPendingFinalizers();</pre>
<p>What does it do?<br />
First call will instruct GC manager to start the process (<a href="http://msdn.microsoft.com/en-us/library/system.gc.collect.aspx" target="_blank">1</a>), while second (<a href="http://msdn.microsoft.com/en-us/library/system.gc.waitforpendingfinalizers.aspx" target="_blank">2</a>) will make sure that we wait for process to be completed.</p>
<p>In the case of the file locks, only after GC has released process which placed the lock in the first place, we can manipulate with the file (ex. delete, rename, move).</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2026 <strong><a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a></strong>. This Feed is for personal non-commercial use only.</span><p>The post <a href="https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/">File locks or when garbage collection goes bad</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.dragonsoft.us/2009/03/02/file-locks-or-when-garbage-collection-goes-bad/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">842</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Minified using Disk
Database Caching 12/89 queries in 0.122 seconds using Disk

Served from: blog.dragonsoft.us @ 2026-09-13 07:41:43 by W3 Total Cache
-->