Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Resource Leakage

Thread view: 
Ramesh - 03 Jun 2006 21:46 GMT
Hi Group -

I am having a doubt regarding the resource cleanup. When we open a
resource we need to close the resource after the usage. For example, a
file, database connection and a socket etc...

Take the following scenarios :

<code>
    public Properties getPropertiesOne(File file) {
        Properties props = new Properties();
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            props.load(in);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                in.close();
            } catch (IOException e) {
                // swallow
            }
        }

        return props;
    }

    public Properties getPropertiesTwo(File file) {
        Properties props = new Properties();
        try {
                props.load(new FileInputStream(file));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        return props;
    }
</code>

The getPropertiesTwo(File file) method is opening the stream but not
closing. Will this cause  a  resource leakage?

Another scenario when we use XSL transformation we pass streams to
XSLTransformer. In these cases how we can ensure that the file opened
is closed? Is this an anti pattern?
Please advice.

Kind Regards,
Ramesh Mandaleeka
steve - 03 Jun 2006 22:56 GMT
> Hi Group -
>
[quoted text clipped - 50 lines]
> Kind Regards,
> Ramesh Mandaleeka

yes, it is a leak

steve


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.