dispose and nothing? whats the main difference?

Discussion in 'ASP .Net' started by =?Utf-8?B?QXNoYQ==?=, Jul 14, 2004.

  1. greetings,
    should i do this

    obj.dispose

    then

    obj = nothing

    both does the same thing right? whats the core difference?
     
    =?Utf-8?B?QXNoYQ==?=, Jul 14, 2004
    #1
    1. Advertising

  2. "Asha" <> wrote in message
    news:...
    > greetings,
    > should i do this
    >
    > obj.dispose
    >
    > then
    >
    > obj = nothing
    >
    > both does the same thing right? whats the core difference?


    No. obj = nothing doesn't do anything anymore. It simply removes one
    reference to the object. If that's the last reference to the object, then
    the object may eventually be garbage-collected.

    Dispose cleans up whatever the object thinks needs to be cleaned up, and
    does it immediately.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jul 14, 2004
    #2
    1. Advertising

  3. Dispose method is used to clean up the unwanted resources like sqlconnections,command objects,

    dispose method will be called automatically if we create the instance in the following way

    using ( DBreader reader=sp.executereader)
    {

    }

    if DBreader is implemented idisposable interface then dispose method will be called
    automatically at the end of scope,

    nothing is used to remove the reference of the object even if we force the object to nothing, it will take some time to relaese the reference by the garbage.
    "Asha" wrote:

    > greetings,
    > should i do this
    >
    > obj.dispose
    >
    > then
    >
    > obj = nothing
    >
    > both does the same thing right? whats the core difference?
     
    =?Utf-8?B?U2FyYXZhbmFuIER1cmFp?=, Jul 14, 2004
    #3
  4. =?Utf-8?B?QXNoYQ==?=

    Scott Allen Guest

    On Tue, 13 Jul 2004 21:37:01 -0700, Saravanan Durai <Saravanan
    > wrote:

    >Dispose method is used to clean up the unwanted resources like sqlconnections,command objects,
    >
    >dispose method will be called automatically if we create the instance in the following way
    >
    >using ( DBreader reader=sp.executereader)
    >{
    >
    >}
    >
    >if DBreader is implemented idisposable interface then dispose method will be called
    >automatically at the end of scope,
    >

    In fact, the only objects you can put inside a using clause are
    objects implementing IDisposable!

    --s
    --
    Scott
    http://www.OdeToCode.com
     
    Scott Allen, Jul 14, 2004
    #4
    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. Showjumper
    Replies:
    2
    Views:
    3,743
    Showjumper
    Jan 20, 2004
  2. Antonio Concepcion
    Replies:
    3
    Views:
    2,737
    Antonio Concepcion
    Feb 17, 2005
  3. exquisitus
    Replies:
    1
    Views:
    12,305
    Eric Sosman
    May 4, 2005
  4. Replies:
    6
    Views:
    697
    James McIninch
    Jan 11, 2005
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    468
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page