Destructors...

P

Paul M

Hi folks,

Given the nature of asp, when I'm constructing data bound middler tier
objects, is it necessary to implement the Idisposable interface or is it
good enough to rely on a Finalize call.

Most of my applications will be using Forms authentication and as such the
sql server connection objects will all have individual user id's i.e. no
connection pooling, and because of the time between posts, I can't see any
reason not rely on the normal garbage collection.

Any comments would be much appreciated...

Thanks...P

P.S Since when did the Oxford English Dictionary spell Finalise with a Z??
Bloomin' nuisance.
 
C

Chris Jackson

Regarding pooling: unless you explicitly turn off pooling in your connection
string, then you will end up with connection pooling with a default number
of 100 connections. If you are using the connections in such a way that you
can't re-use them, then this pool will diminish even faster. This could
cause problems as your user base expands.

Regarding IDisposable: Unless you need to hold in the state of your object
some scarce resources, then you have no reason to expose this interface
yourself. You should, however, make a point to properly use this interface
in the objects you are using that expose this interface. If you are using
C#, you can use the using keyword to make this easy. For example:

using (SqlConnection myConnection = new SqlConnection(...)) {
// do something with the connection
}

Using functions in much the same way as a try ... finally clause would,
guaranteeing to call Dispose as soon as you are done using the connection,
either releasing it to the pool or else returning those resources to the
system. With scare resources, you should make it a point to free them up as
soon as you have the opportunity to do so. Because garbage collection is
non-deterministic, you could run out of your scarce resources long before
you run out of the resources that trigger garbage collection.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top