Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to release object stored in property?
Message
 
 
To
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:
01397396
Views:
36
I also unfortunately don't have that book, so my recollections a bit vague.

I think your declaration should be

public class MyPage : BasePage:iDisposable

same for your inner classes.

Then you also can create explicit destructor for each of this class and call dispose of the inner objects there.

The mentioned book had this whole concept coded using some special property to know how the descructor was called.

>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
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform