Finalize sub

Discussion in 'ASP .Net' started by =?Utf-8?B?U2FsYW1FbGlhcw==?=, Oct 1, 2006.

  1. I started to use the Finalize sub in aspax page, I put a break point on one
    of the lines, hit run with debug, the pages dispalys without breaking on the
    line.

    2nd question, do we need to use the keyword "set" as normal vb to set an
    object to nothing or it is enough todo the following
    "myobject = nothing"
    instead of
    "set myobject = nothing "
    Thanks
    =?Utf-8?B?U2FsYW1FbGlhcw==?=, Oct 1, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?U2FsYW1FbGlhcw==?=

    Mark Rae Guest

    "SalamElias" <> wrote in message
    news:...

    >I started to use the Finalize sub in aspax page, I put a break point on one
    > of the lines, hit run with debug, the pages dispalys without breaking on
    > the
    > line.


    What point are you making...?

    > 2nd question, do we need to use the keyword "set" as normal vb to set an
    > object to nothing or it is enough todo the following
    > "myobject = nothing"
    > instead of
    > "set myobject = nothing "


    "Normal VB"???

    You need to stop thinking of VB.NET as the next version of VB6 - apart from
    some obvious syntactic similarities, the two languages are pretty much
    completely different...
    Mark Rae, Oct 1, 2006
    #2
    1. Advertising

  3. For the first point, I don't how to be more clearthat that:
    I am putting a breakpoint which I don't go through in debug operation?
    I pass in Page_load, init and others except the Finalize

    Hope this would be more clear

    regarding VB, Iknow it is completly differnet, but I was wondering because I
    am having strange /bizarre behavior in code setting obectstonothingin whenI
    use the VBnet syntax
    myobject =nothing

    By normal VB Imeant VB6

    Thanks

    "Mark Rae" wrote:

    > "SalamElias" <> wrote in message
    > news:...
    >
    > >I started to use the Finalize sub in aspax page, I put a break point on one
    > > of the lines, hit run with debug, the pages dispalys without breaking on
    > > the
    > > line.

    >
    > What point are you making...?
    >
    > > 2nd question, do we need to use the keyword "set" as normal vb to set an
    > > object to nothing or it is enough todo the following
    > > "myobject = nothing"
    > > instead of
    > > "set myobject = nothing "

    >
    > "Normal VB"???
    >
    > You need to stop thinking of VB.NET as the next version of VB6 - apart from
    > some obvious syntactic similarities, the two languages are pretty much
    > completely different...
    >
    >
    >
    =?Utf-8?B?U2FsYW1FbGlhcw==?=, Oct 1, 2006
    #3
  4. =?Utf-8?B?U2FsYW1FbGlhcw==?=

    Mark Rae Guest

    "SalamElias" <> wrote in message
    news:...

    > For the first point, I don't how to be more clearthat that:
    > I am putting a breakpoint which I don't go through in debug operation?
    > I pass in Page_load, init and others except the Finalize


    Hmm - you have a Finalize in your aspx page's code-behind? Are you actually
    *instantiating* this class, then...? Do you know what Finalize is...?

    > regarding VB, Iknow it is completly differnet, but I was wondering because
    > I
    > am having strange /bizarre behavior in code setting obectstonothingin
    > whenI
    > use the VBnet syntax
    > myobject =nothing


    No - the behaviour you are getting is perfectly normal. On the other hand,
    it might not be - it's difficult to tell, as you don't actually say what the
    behaviour is that you consider to be strange / bizarre...

    > By normal VB Imeant VB6


    Sigh...
    Mark Rae, Oct 1, 2006
    #4
  5. You would almost never need to implement Finalize in an aspx page, the entire
    page class is extinguished and goes out of scope as soon as the page has been
    rendered. What makes you believe that just because you put a "Finalize Sub"
    in your page class that something is going to call this method?

    In actual fact, finalizers only need to be implemented when you hold onto
    resources that need cleaning up.

    Hope that helps.
    Peter


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




    "SalamElias" wrote:

    > I started to use the Finalize sub in aspax page, I put a break point on one
    > of the lines, hit run with debug, the pages dispalys without breaking on the
    > line.
    >
    > 2nd question, do we need to use the keyword "set" as normal vb to set an
    > object to nothing or it is enough todo the following
    > "myobject = nothing"
    > instead of
    > "set myobject = nothing "
    > Thanks
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Oct 1, 2006
    #5
  6. Hi SalamElias,

    Welcome to VB.NET!

    The Set and Let keywords are no longer needed/supported in VB.NET.

    To understand why the Finalize method is not called during debug, you need
    to first understand what is Garbage Collection by reading following
    excellent article by Jeffrey Richter:

    #Garbage Collection: Automatic Memory Management in the Microsoft .NET
    Framework -- MSDN Magazine, November 2000
    http://msdn.microsoft.com/msdnmag/issues/1100/gci/

    For more information, please refer to following articles:

    #Object.Finalize Method (System)
    http://windowssdk.msdn.microsoft.com/en-us/library/system.object.finalize.as
    px

    #Finalizers, Assembly Names, MethodInfo, and More
    http://msdn.microsoft.com/msdnmag/issues/04/05/NETMatters/

    #Implementing Finalize and Dispose to Clean Up Unmanaged Resources
    http://windowssdk.msdn.microsoft.com/en-us/library/b1yfkh5e.aspx


    Please feel free to let me know whether or not you need further
    information. Thank you.


    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Oct 2, 2006
    #6
  7. In fact I have objects declared on the page level, used by different Subs, so
    I can not destroy them inside each sub, I need to have one place at the very
    end of execution to destroy those objects.
    This is the problem. Is there any alternative to use the finalize.
    I will try to read the different articles and let you know

    Thanks

    "Walter Wang [MSFT]" wrote:

    > Hi SalamElias,
    >
    > Welcome to VB.NET!
    >
    > The Set and Let keywords are no longer needed/supported in VB.NET.
    >
    > To understand why the Finalize method is not called during debug, you need
    > to first understand what is Garbage Collection by reading following
    > excellent article by Jeffrey Richter:
    >
    > #Garbage Collection: Automatic Memory Management in the Microsoft .NET
    > Framework -- MSDN Magazine, November 2000
    > http://msdn.microsoft.com/msdnmag/issues/1100/gci/
    >
    > For more information, please refer to following articles:
    >
    > #Object.Finalize Method (System)
    > http://windowssdk.msdn.microsoft.com/en-us/library/system.object.finalize.as
    > px
    >
    > #Finalizers, Assembly Names, MethodInfo, and More
    > http://msdn.microsoft.com/msdnmag/issues/04/05/NETMatters/
    >
    > #Implementing Finalize and Dispose to Clean Up Unmanaged Resources
    > http://windowssdk.msdn.microsoft.com/en-us/library/b1yfkh5e.aspx
    >
    >
    > Please feel free to let me know whether or not you need further
    > information. Thank you.
    >
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    =?Utf-8?B?U2FsYW1FbGlhcw==?=, Oct 2, 2006
    #7
  8. Hi,

    Everytime a request is served by your page class, a instance of your page
    class is recreated. Normally you don't have to explicitly destroy the
    objects, even if they're declared on the page level. In fact, when
    programming in .NET, you seldomly need to free/destroy your objects
    explicitly. The Garbage Collector will free/destroy them at appropriate
    time. If your object holds unmanaged resource, then you need to free them
    in the Finalize method. However, when the Finalize method is called is
    determined by the GC.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Oct 2, 2006
    #8
    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. z. f.

    throw exception in the finalize

    z. f., Jul 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    430
    avnrao
    Jul 5, 2004
  2. Ben
    Replies:
    2
    Views:
    883
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,021
    Lawrence D'Oliveiro
    May 20, 2011
  4. andrey
    Replies:
    0
    Views:
    160
    andrey
    Dec 15, 2007
  5. Andrey Nikitin
    Replies:
    1
    Views:
    168
    Nobuyoshi Nakada
    Dec 16, 2007
Loading...

Share This Page