ASP.NET Object Disposal

Discussion in 'ASP .Net' started by mukulprabhu@gmail.com, Aug 20, 2006.

  1. Guest

    Hello there,

    Is it compulsory that the component objects created in code behind
    should be disposed explicitly.

    For eg.

    first.cs
    index.aspx.cs
    -----------------------------------------------------
    -----------------------------------------------------
    Class first first
    objFirst = new first();
    {
    page_load()
    method A () {some code} {
    }
    objFirst.A();
    }

    in the above example is it nessesary to dispose "objFirst" object.

    Anticipating your reply.

    Thanx in advance.
    , Aug 20, 2006
    #1
    1. Advertising

  2. Mukul,

    I never dispose my component objects explicitly. I wonder what gave you
    the idea? I am assuming you are putting first.cs in App_Data (assuming
    you are using .NET 2.0) but nevertheless the Garbage Collection should
    handle this.

    Sarat

    wrote:
    > Hello there,
    >
    > Is it compulsory that the component objects created in code behind
    > should be disposed explicitly.
    >
    > For eg.
    >
    > first.cs
    > index.aspx.cs
    > -----------------------------------------------------
    > -----------------------------------------------------
    > Class first first
    > objFirst = new first();
    > {
    > page_load()
    > method A () {some code} {
    > }
    > objFirst.A();
    > }
    >
    > in the above example is it nessesary to dispose "objFirst" object.
    >
    > Anticipating your reply.
    >
    > Thanx in advance.
    Sarat Pediredla, Aug 20, 2006
    #2
    1. Advertising

  3. Objects normailly do not need to be disposed unless they have resources or
    referencess to other objects that have unmanaged resources that need to be
    disposed (file handles, bitmaps, network streams, sockets, connections, etc.)

    If your object has a Dispose method, you can call it, or have your class
    implement the IDisposable pattern and it can call it.
    Otherwise, objects are destroyed automatically by the runtime and in the
    case of an ASP.NET page, everything goes away anyway as soon as the page
    lifecycle is complete and the HTML has been sent out to the browser.

    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "" wrote:

    > Hello there,
    >
    > Is it compulsory that the component objects created in code behind
    > should be disposed explicitly.
    >
    > For eg.
    >
    > first.cs
    > index.aspx.cs
    > -----------------------------------------------------
    > -----------------------------------------------------
    > Class first first
    > objFirst = new first();
    > {
    > page_load()
    > method A () {some code} {
    > }
    > objFirst.A();
    > }
    >
    > in the above example is it nessesary to dispose "objFirst" object.
    >
    > Anticipating your reply.
    >
    > Thanx in advance.
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Aug 21, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cameron

    DirectoryEntry Disposal Test

    cameron, Apr 13, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    505
    Willy Denoyette [MVP]
    Apr 14, 2004
  2. Roger Twomey
    Replies:
    3
    Views:
    755
    Chris R. Timmons
    Feb 18, 2005
  3. TCORDON

    DataSet Disposal

    TCORDON, Mar 22, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,572
    JiangZemin
    Mar 23, 2005
  4. patrick

    disposal of object

    patrick, Dec 20, 2007, in forum: Java
    Replies:
    3
    Views:
    328
    Thomas Kellerer
    Dec 20, 2007
  5. Amadrias

    Session object correct disposal

    Amadrias, May 3, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    100
    Amadrias
    May 3, 2006
Loading...

Share This Page