• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resource leak

 
K Sekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We heard about the case where the application will cause resource leakage
if we fail to close the resources properly.

Existing snippet :

try{

// using I/O Stream

// closing the resource

}
catch(IOException e){
//Log the Exception
}

Assume that there exists a issue(say I/O operations) which prevents the execution of the program to close the resource.

Modified snippet :

try{

// using I/O Stream

// closing the resource

}
catch(IOException e){
//Log the Exception
}
finally{
// null check
// close the resource
}

The thing is I need to replicate the problem so as to test
whether the introduction of finally block forces the program
to close the resource.

Can anyone help me in replicating the resource leakage problem?


Thanks In Advance.
Kannan
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's quite easy:

Try the following with and without the closing:
- start the program
- delete the file from Windows
- press enter in the program

If you don't close the stream Windows cannot delete the file because it's still in use (until the Java program exists, hence the System.in.read()).
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy kannan!

We being a very friendly community, do not have much rules but there is a naming policy that we are very strict about!
Unfortunately, your display name does not follow the policy. Please take a moment to change the same.

I see that you have been in the ranch for long. Is it so that you have been bitten by the this google chrome bug?
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name was Kannan Dhanasekaran before, so that's why there was no previous warning.
 
K Sekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many Thanks Prime.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kannan, are you by chance using Google Chrome as your browser? It has a bug that sometimes sets your display name even though you don't want it to.

Can you please change it back, and keep that in mind while using Chrome?
 
K Sekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya Sure .
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kannan, I do not think you understood what we are asking you to do. Your display name still violates the naming policy.
It may be because of the google chrome bug but please take a moment to change it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!