Finalize sub

G

Guest

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
 
M

Mark Rae

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...
 
G

Guest

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
 
M

Mark Rae

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...
 
G

Guest

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
G

Guest

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top