Solved

clean-up resources

Posted on 2000-05-11
7
150 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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 40 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outlook opens HTML email as text 4 31
Little bit of help styling my heading 3 31
html border input line 7 15
Do alert on select 6 14
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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