Click here to Skip to main content
15,891,607 members
Articles / Containers / Virtual Machine

Observable property pattern, memory leaks, and weak delegates for .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (42 votes)
4 Dec 200624 min read 218.3K   359   174  
This article is dedicated to the observable property design pattern, a very nice pattern used in the Microsoft .NET Framework, a possible memory leak problem with it, and gives a couple of ways to solve it.
#region License
/*
Copyright (c) 2006 Alexey A. Popov

	Permission is hereby granted, free of charge, to any person
	obtaining a copy of this software and associated documentation
	files (the "Software"), to deal in the Software without
	restriction, including without limitation the rights to use,
	copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following
	conditions:

	The above copyright notice and this permission notice shall be
	included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
	OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

using System;
using System.Globalization;
using System.Reflection;
using System.Resources;

namespace Pvax.WeakDelegates
{
	/// <summary>
	/// Resource dispenser.
	/// </summary>
	internal class RD
	{
#if NET11
		const string stringResources = "strings";
#endif
#if NET20
		const string stringResources = "Pvax.WeakDelegates.strings";
#endif

		RD()
		{}

		private static readonly ResourceManager rm = new ResourceManager(stringResources, Assembly.GetExecutingAssembly());

		internal static string GetString(string resourceId)
		{
			return rm.GetString(resourceId);
		}

		internal static string GetStringFormat(string resourceId, params object[] args)
		{
			return String.Format(GetString(resourceId), args);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'm a system administrator from Moscow, Russia. Programming is one of my hobbies. I presume I'm one of the first Russians who created a Web site dedicated to .Net known that time as NGWS. However, the Web page has been abandoned a long ago.

Comments and Discussions