.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

EventListeners and Garbage Collection

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

If I have a collection of objects that all have a PropertyChanged event (they implement INotifyPropertyChanged).  If I add a listener to the PropertyChanged events for all the objects in that collection, but start removing those objects will I create a memory leak, by not deattaching the listener before removing the object?  I.e. will I prevent garbage collection from happening for those objects or the listeners?

View Complete Post

More Related Resource Links

Garbage Collection-Part 2: Automatic Memory Management in the Microsoft .NET Framework


The first part of this two-part article explained how the garbage collection algorithm works, how resources can clean up properly when the garbage collector decides to free a resource's memory, and how to force an object to clean up when it is freed. The conclusion of this series explains strong and weak object references that help to manage memory for large objects, as well as object generations and how they improve performance. In addition, the use of methods and properties for controlling garbage collection, resources for monitoring collection performance, and garbage collection for multithreaded applications are covered.

Jeffrey Richter

MSDN Magazine December 2000

Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework


Garbage collection in the Microsoft .NET common language runtime environment completely absolves the developer from tracking memory usage and knowing when to free memory. However, you'll want to understand how it works. Part 1 of this two-part article on .NET garbage collection explains how resources are allocated and managed, then gives a detailed step-by-step description of how the garbage collection algorithm works. Also discussed are the way resources can clean up properly when the garbage collector decides to free a resource's memory and how to force an object to clean up when it is freed.

Jeffrey Richter

MSDN Magazine November 2000

Garbage Collection

I have some understanding of Garbage collection but need some more clarifications. Which all are unmanaged and managed resources? Is database connection an unmanaged resource, if I open a database connection would I be creating an unmanaged resource. What is the difference b.w finalize and dispose. Do I have to call dispose for both managed and unmanaged resources or finalize method for umanaged resources. Setting objects = null, does that mean it clears out the memory allocated to them.   Thanks.

Long running WPF application - Garbage Collection

Hi All, I have a long running WPF application; users start the application and keep it open for at least 6 hours straight. I spend a couple days with a Memory Profiler, solving a couple of memory leaks. According to the Memory Profiler, all is good now. However, when I run the application, and monitor the Memory in the Windows Task Manager, it only seems to grow. When I create a button to force the garbage collection (GC.Collect()), a lot of memory is freed from the app. My questions: 1. I don't feel like it's a good idea to call GC.Collect() explicitly; is there any case where it is advised to do so? 2. Is it normal that it takes WPF that long to start garbage collecting automatically? Thanks, Koen

Speed issues with ReaderWriterLockSlim and Garbage Collection


I have an example piece of code the illustrates issues in my code when GC.Collect is carried out on a class having a ReaderWriterLockSlim member variable. The GC.Collect takes between 2 and 3 seconds to run. I need to carry out GC at regular intervals because my applicaton is extremely memory intensive.

namespace WpfApplication12


 public class DataItem


  private readonly ReaderWriterLockSlim m_propertyLock = new ReaderWriterLockSlim();

  public DataItem()




 /// <summary>

 /// Interaction logic for Window1.xaml

 /// </summary>

 public partial class Window1 : Window


  public Window1()



   List<DataItem> dataItemList = new List<DataItem>();


Garbage collection in this example, true or false?


when using this code:  

string s;
s = "wombat";
s += " kangaroo";
s += " wallaby";
s += " koala";


they tell me: only the last string has a reference, the other three will be disposed of during garbage collection.


So what does this mean exactly?

string s got only the reference of "koala"? or a reference to "wombat"??



disable Garbage Collection


Plz make me suggestion:

I want to implement logic to garbage collector using c#.net. i.e. want to code to do GC in my own logic. So my Questions are:

1. Where should i write code to do it?

2. If it is c#.Net. how do i disable or restrict .Net Framework to auto collect garbage?


Please advice me for above question.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)


Hey guys

I came across this bug using while trying to implement a sitemap

Line 147:						Panel panel = new Panel();
Line 148:						panel.Controls.Add(_viewState);
Line 149:						Page.Form.Controls.Add(panel);
Line 150:						string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Extender.MakeChildId("UL") + "');";
Line 151:						Page.ClientScript.RegisterOnSubmitStatement(typeof(TreeViewAdapter), _viewState.ClientID, script);

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +8696951
   CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in E:\wwwroot\ThirdParty\CSSFriendly\CSSFriendly_24242\CSSFriendly\TreeViewAdapter.cs:149
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +8901848
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148

CLR Inside Out: Profiling the .NET Garbage-Collected Heap


In this article, the authors complete the picture for Garbage Collected (GC) heap related memory issues by providing step-by-step instructions on using the CLR Profiler for .NET GC heap memory investigations.

Subramanian Ramaswamy, Vance Morrison

MSDN Magazine October 2009

Basic Instincts: Collection and Array Initializers In Visual Basic 2010


Collection Initializers are a great addition to the language and allows concise syntax in order to initialize both framework and user defined collection types.

Spotty Bowles

MSDN Magazine October 2009

How to Cache System.Collection.Generic.List object


I need to cache System.Collection.Generic.List object with expiration time

var Root = from feed in feedhotel.Descendants(ota + "HotelContent")
                           where (feed.Attribute("HotelCode") != null)
                           select new xmlhotel()




return Root.ToList();

Is it possible to cache Root.ToList() for some time....

Finding a control from a control collection



I'm trying to write a bit of code that will format all the numeric values in lables in my gridview. here's what i am doing right now:

On the RowDataBound Event, i create a row object for the row that is currently being bound.
then i go use the FindControl method to grab each label by name.

Problem is there's too many columns in this table and i really dont wnat to have to type it all out. Here's an example of what i am currently doing

' Get row being bound
Dim myRow = e.Row

' Get labes to be formatted
Dim lblMunicipalIncineration = CType(myRow.FindControl("lblMunicipalIncineration"), Label)

' format labels
If lblMunicipalIncineration IsNot Nothing Then
    If Not String.IsNullOrEmpty(lblMunicipalIncineration.Text) Then
        lblMunicipalIncineration.Text = FormatNumber(lblMunicipalIncineration.Text, 0, TriState.False, TriState.False, TriState.True)
    End If
End If

Can i use myRow.Controls to grab a list of all the controls and then somehow get a list of all labels in the collection and then use a for loop to go through and format each label?

Multiple services in REST Collection WCF Service?


After I create a "REST Collection WCF Service" project, it contains one service "service.svc". Can I add multiple services to this project? There must be a way to do so. Otherwise, it does not make sense to create one project for each service.


My question is how to add a new service to an existing "REST Collection WCF Service" project?


Thanks a lot.

Site Collection Usage Summary: No Data Available


Usage analysis processing is enable for my farm in both Central Administration and in the SSP.

I've checked TImer Job Status and the three timer jobs responsible for doing the log analsis are all running.

I've also checked the log file locations and the log files are being generated.

Yet when I browse the "Site collection usage summary" report (SpUsageSite.aspx) I get the following:

No data is available for this report. Usage analysis might have been enabled only recently, or there might have been insufficient usage to result in any values for the report.

My farm is running 2007 Enterprise SP2 (

Can someone confirm if this issue was fixed with one of the CU's that were issues post-SP2?

Site Collection Usage Report Include Outlook?


Hi all,

Does anyone know if the Site Collection Usage Report includes activity that occurs from Outlook? For example, if a user contributes to a discussion board without ever physically touching the site or if the user just reads list content from Outlook, is this included?

ANY help at all is greatly appreciated.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend