• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Resource leak

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()).
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks Prime.
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya Sure .
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic