Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to release object stored in property?
Message
From
01/05/2009 06:13:51
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01397173
Message ID:
01397384
Views:
46
Hi,
The book mentioned is out of stock at this moment. However, I have went through some other similar book titles and some online articles. All of them also talk about destructor and IDisposable pattern. Neither of them talk about dangling reference memory clean up. Would it be handled by GC automatically?

For more info, I have object relationship as below
public class MyPage : BasePage
{
  //-- MyBO will be stored at session
  private MyBO _myBO = new MyBO();

  private void Page_Load(Object sender, EventArgs e)
  {
    //-- this actually via ASP.NET inline markup and will refer to _myBO to show data
    this.Controls.Add(new MyDataGridView());

    this._myBO.SomeEvent += this.MyBO_SomeEvent;
  }

  private void MyBO_SomeEvent()
  {
    // do something
  }
}

public class MyDataGridView : DataGridView
{
  public MyDataGridView()
  {
    this.Templates.StatusBar = new StatusBarTemplate(this);
  }
}

public class StatusBarTemplate : ITemplate
{
  private MyDataGridView _grid;
  private Button _button = new Button();

  public StatusBarTemplate(MyDataGridView grid)
  {
    this._grid = grid;
  }

  public void InstantiateIn(Control container)
  {
    this.Controls.Add(this._button);
    this._button.DataBound += this.Button_DataBound;
  }

  public void Button_DataBound(Object sender, EventArgs e)
  {
    this._button.Enabled = this._grid.SomeMethod();
  }
}
I use ANT profiler to trace the memory, and I found that some objects is not released (new object created) after every postback.

1. MyBO.SomeEvent
2. Button
3. MyDataGridView

Question: How could I free up them upon every postback? In which event/method should I place code to nullify the child object?

Thank you
I am not the most powerful man in this world.
I am not the worst man in this world either.
I just as same as all of you.
I still need to learn from my mistakes...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform