Solved

clean-up resources

Posted on 2000-05-11
7
148 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert text field data into html script 13 42
how to avoid redundand ajax calls 5 30
Which non-HTML GUI front end to use with Java? 3 22
VBScript on Html 8 12
Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

821 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