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

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

disable Garbage Collection

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :WPF

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.

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

EventListeners and Garbage Collection


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?

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

disable top level site collection


I saw some compaies when they created sharepoint web application, they do not create a top level site collection.  thety created site collections under managed path. For example, the sharepoint web app called http://MyCompanyNmae.com. users can not access http://MyCompanyNmae.com directly. Instead they have to access through






Why they disable the top level site collection? for what purpose?


Thanks in advance,  


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"??



Use Membership but bypass / disable password usage for users


I have an application that does LDAP authentication. The authentication is done on the code behind page of my Login.aspx page. Once the user passes LDAP authentication, a cookie is set and I redirect:

FormsAuthentication.RedirectFromLoginPage(UserName.Text, False)

I would like to setup membership in my application and keep track of some user information. But due to company security requirements, I cannot store user passwords on my application. That must stay on the LDAP server only.

Is there a way to store users but disable password storage on the aspnet_membership table?

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

Disable check box in a gridview does not working



I have a check box in a template field in a gridview.

Based on some condition, I want those check boxs to  be enable and disable.

I am trying the below code but does working..

 protected void GVstudents_RowDataBound(object sender, GridViewRowEventArgs e)
              if (e.Row.RowType == DataControlRowType.DataRow)
                    string studentID = GVstudents.DataKeys[0].Value.ToString();
                    int stdID = Convert.ToInt32(studentID);
                    int schID = profile.getSchoolIDByStudentID(stdID);
                    int tchrID = profile.getTeacherIDByStudentID(stdID);

                    if (patti.chkIsTeacherPaid(stdID, schID, tchrID))
                        CheckBox cb = (CheckBox)e.Row.FindControl("chkTeacherPayment");
                        cb.Enabled = false;
                        cb.Checked = true;


any help??

Disable filtering on a Dynamic Data list view.


I have an entity set of NotificationTemplates, and each one of these has a collection of zero-many SmsTemplate entities. When editing or viewing a NotificationTemplate, I have a link to View SMS Templates. That link takes me to a List view for the SmsTemplates entity set, filtered for the NotificationTemplate I was viewing.

How can I prevent the user changing this filter to show SmsTemplates for another NotificationTemplate? That is, I want the filter, but it must be read only. The drop-down just mustn't drop down, it must just display the name of the NotificationTemplate that these SmsTemplates belong to. To view SmsTemplates for another NotificationTemplate, the user must click View SMS Templates from that other template.

This was originally asked by myself on SatckOverflow at: http://stackoverflow.com/questions/3514373/disable-filtering-on-a-dynamic-data-list-view

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....

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