473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

should i close statement having local reference ?????

dmjpro
2,476 2GB
look at this code carefullyyyy .....

void test(Connection l_con)
{
Statement l_stmt = l_con.createStatement();
l_stmt.close(); //Sholud i do this to avoid maximum cursors open error
}
i mean when the method calling finished then the local reference l_stmt will be destroyed then will JVM close all resources associated with it ....

plz explain me in details ....

thanx
Mar 14 '07 #1
14 1374
r035198x
13,262 8TB
look at this code carefullyyyy .....



i mean when the method calling finished then the local reference l_stmt will be destroyed then will JVM close all resources associated with it ....

plz explain me in details ....

thanx
Yes you should close it yourself. The JVM may close it before garbage collecting but that depends on the platform.
Mar 14 '07 #2
dmjpro
2,476 2GB
oh really .... is this true .....

could u say me one more thing does the JVM provided by SUN has this facility ...

plz say ....

thanxxxxx
Mar 14 '07 #3
r035198x
13,262 8TB
oh really .... is this true .....

could u say me one more thing does the JVM provided by SUN has this facility ...

plz say ....

thanxxxxx
Garbage collection like Concurrency is one of those things in Java that are not platform independant. You cannot say when a useless variable's contents are removed from memory. Even is you call System.gc(), garbage collection may not occur. It depends on the memory algorithms of the OS you are using. So leaving a connection open and hoping it will get closed on cleanup is not safe because you never know when clean up actually takes place.
Mar 14 '07 #4
dmjpro
2,476 2GB
thanx for ur detail info ... thanxxxxx
Mar 14 '07 #5
dmjpro
2,476 2GB
oh sorry i forget to mention ....

i don't understand the secind line ...

plz explain me in details ...........
Mar 14 '07 #6
r035198x
13,262 8TB
oh sorry i forget to mention ....

i don't understand the secind line ...

plz explain me in details ...........
which line, dj?
Mar 14 '07 #7
dmjpro
2,476 2GB
sorry i misspell ......

the second line....

plz say .... thanx
Mar 15 '07 #8
r035198x
13,262 8TB
sorry i misspell ......

the second line....

plz say .... thanx
Assuming you mean this:"You cannot say when a useless variable's contents are removed from memory."

A variable holds the address of where an object is stored in memory.

If you have

Expand|Select|Wrap|Line Numbers
  1.  
  2. Double x = new Double(3); //memory for Double(3) object
  3. Double y = new Double(5); //memory for Double(5) object
  4.  
Then after
Expand|Select|Wrap|Line Numbers
  1.  x = y; 
The variable x is no longer refering to the object Double(3), but is now refering to the Double(5) object. The Double(3) object is no longer being referenced and there is no longer any way of accessing it now. We say that it is ligible for garbage collection. However, you cannot say whether it has been removed from memory yet. It is the duty of the garbage collector to remove that Double(3) object from memory and we don't know when exaclt the GC is going to remove that object from memory even though it is now useless.
Mar 15 '07 #9
dmjpro
2,476 2GB
ok now i can understand ur words ....

many many thanxxxx
Mar 15 '07 #10
Assuming you mean this:"You cannot say when a useless variable's contents are removed from memory."

A variable holds the address of where an object is stored in memory.

If you have

Expand|Select|Wrap|Line Numbers
  1.  
  2. Double x = new Double(3); //memory for Double(3) object
  3. Double y = new Double(5); //memory for Double(5) object
  4.  
Then after
Expand|Select|Wrap|Line Numbers
  1.  x = y; 
The variable x is no longer refering to the object Double(3), but is now refering to the Double(5) object. The Double(3) object is no longer being referenced and there is no longer any way of accessing it now. We say that it is ligible for garbage collection. However, you cannot say whether it has been removed from memory yet. It is the duty of the garbage collector to remove that Double(3) object from memory and we don't know when exaclt the GC is going to remove that object from memory even though it is now useless.
I hear you r0.
But Remember there are also primitive values to take care of. The Statement "A variable holds the address of where an object is stored in memory" May not necessarily hold coz primitives are not objects .... a java trade off from object orientation, for practicality........ A primitive variable actually holds the bit pattern of the value it represents.
My question is :Does that mean primitives are never garbage collected
Mar 15 '07 #11
dmjpro
2,476 2GB
yes why not .... i think u didn't get ros' point of view ........

he answered my question perspective ..... the primitive datas are garbage collected
Mar 15 '07 #12
r035198x
13,262 8TB
yes why not .... i think u didn't get ros' point of view ........

he answered my question perspective ..... the primitive datas are garbage collected
Anything that has memory reserved for it can be garbage collected. So I should have included the primitive types there. Of course the primitives are stored in a different manner than objects are. Primitives are stored in constant size memory. I should probably have also included the special way that Strings are handled but I thought that might have clouded the issue at hand.
Mar 15 '07 #13
Anything that has memory reserved for it can be garbage collected. So I should have included the primitive types there. Of course the primitives are stored in a different manner than objects are. Primitives are stored in constant size memory. I should probably have also included the special way that Strings are handled but I thought that might have clouded the issue at hand.

I am new to this forumn, but so far I am impressed. Thanks. It's nice to be around "Real" java developers...I didn't mean to cloud the thread. Just an open mind taht scrutinises.

I hear u on the String object storage and immutability. I will let you post it on one of those tutorial postings that you so much keep updated.

Keep it up. I'm impressed
Mar 15 '07 #14
dmjpro
2,476 2GB
actually here the point u can understand clearly that how garbage collection depends on the meory issue of the OS .....

thanx N002199B u made me more clear ........

thanxxxxxx aallottt of thanxxxx
Mar 15 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: Greg Merideth | last post by:
I was looking for a way to pass, by reference, a class to a webmethod to allow the web method to alter the values of some (now) 50 variables of the class. Now, to get this to work, I have to put...
15
by: matko | last post by:
Hi! In one of the two examples for the PaintEventArgs.Graphics-property (in the VS 2005 documentation), the Graphics-object is "saved" to a local variable, before being used. In the other...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
2
by: Jeff | last post by:
Hello, I assigned a new object to a local variable ("req") in a function (see below). The local variable "req" is obviously destroyed when the function exits, but should the object referenced by...
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
3
by: digz | last post by:
This is a very simplified version of something I am trying to understand. The State object holds the strings and maps , and I pass a reference to State to the process Function which manipulates it...
23
by: Tony Johansson | last post by:
Hello! I just wonder what is the point of having the reader variable declared as TextReader in the snippet below.. Is it because of using the polymorfism on the reader variable perhaps. using...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.