?
Solved

clean-up resources

Posted on 2000-05-11
7
Medium Priority
?
158 Views
Last Modified: 2010-04-09
What is the best way to clean-up after an object that uses ResultSet,Connection and Statement objects?
I wrote close() method which closes these objects (by using their close method:Connection.close(),ResultSet.close() etc,
but I have to put all in a try block so what happens if an exception is thrown?
Another issue - what if  the class which uses those objects is the main class
and no one calls its close() method?
0
Comment
Question by:twg
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 2799859
You use ASP, right, then you should set your objects to nothing after you've closed them.always nothing your objects, that's the way to clean up memory

Conn.Close
Conn = nothing
0
 

Author Comment

by:twg
ID: 2799879
thanks CJ S but I don't use ASP.
Anyway, the problems still stay open(if an exception is thrown, and how can I garantee clean-up for the main class
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2799907
then what do you use, VBscript? That's also nothing

javascript is null

javascript:
object = null
vbscript:
object = nothing
asp = vbscript:
object = nothing

that'll ganarantue the clean up.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:twg
ID: 2799966
I wrote my application in Java and it uses the java.sql package. I'm sorry that I didn't write my question in the right section (java programming) so can you pass my question to the relevant people?
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 80 total points
ID: 2800022
totally depends on how you have set your program up. One should use as little gloabl variables as you can. This means that there are no variables outside your functions. If the variables are all inside your functions, they'll get deleted right away when they loose their scope.
If you used the new operator, then you should use the free-method.
Java usesit's own handles, everything is inherited from it's parent, there's no need for you to free them. Just closing _should_ be enough for normal stuff.
0
 

Author Comment

by:twg
ID: 2800114
I wrote my application in Java and it uses the java.sql package. I'm sorry that I didn't write my question in the right section (java programming) so can you pass my question to the relevant people?
0
 
LVL 2

Expert Comment

by:lilian_kelly
ID: 2800121
PART 1
_______

Use the finally clause....

try{
 
}
catch(Exeption e){
   // handle exception
}
finally
{
  // can clean up stuff here
}

EXCEPTION THROWN
If an exception occurs in the try block, and there is an associated catch block to handle the exception , control transfers to the catch block and then to the finally block

TRY BLOCK COMPLETES
If control reaches the end of the try , it then proceeds to the finally block.


PART 2
_______
You should really make sure that the close is called. But you can use the finalize()method. This method is called by the garbage collector calls before it collects the objects in memory. But there is a problem, you have no gaurantee that any objects will be garbage collected...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question