|
-
Aug 28th, 2002, 03:45 PM
#1
Shared members and Finalize
If I have a class that has a Shared SQLConnector in it where do I put my clean up code? Or do I not put it?
I mean is there a way to tell if there are no more instances of the class left and then perform the clean up in an Overrides Finalize method? Or is it safe to assume the garbage collection will handle this good enough?
The connection isn't left open so the main clean up is just to make sure its set back to nothing or maybe a backup check to make sure it IS closed and if not to close it (although like I said it shouldn't be open anyway).
Or do you think I should just share a string instead and use it as the connection string instead of the whole connection object?
-
Aug 29th, 2002, 03:02 AM
#2
Addicted Member
I think you should always close and clear up a connection esp. across a busy network. The garbage collector, although a great idea, doesn't have any routinue so you don't know how long before it will tidy up for you.
Is using a shared connection the best idea?? How do you know if all objects have finished using it? I usually open a connection everytime i want a dataset/reader and then close it immediately. Maybe I'm doing it oldy style? Only my thoughts?!
Wind and waves resolves all problems.
-
Aug 29th, 2002, 03:22 AM
#3
I do only open and close it when needed but there are a series of items of the same class that will be using the same connection so I made it shared so they can automatically use the same one automatically. Where would you put your clean up code then? If I use Finalize then it is only the Finalize for that instance not all the instances thats kind of the problem. Thanks.
-
Aug 29th, 2002, 03:57 AM
#4
Addicted Member
Microsoft says
There is a slight performance penalty for executing Sub Finalize, so you should define a Sub Finalize method only when you need to release objects explicitly.
I have a closeconn sub which i call after i get my dataset etc.
You imply that the shared connection is within the class
series of items of the same class that will be using the same connection
If you use the sub finalize that will kill off the shared connection. Creating a new instance of the class will then create a new instance of the shared connection - don't really see the problem?
Wind and waves resolves all problems.
-
Aug 29th, 2002, 04:11 AM
#5
Then I'd have to recreate it everytime I made a new instance defeating the purpose of having it shared.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|