Solved

clean-up resources

Posted on 2000-05-11
7
146 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now