• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is closing?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't understand what close() does exactly.

i read the API and went to stackflow, but i still can't get a grasp.
for example, what does "releasing the resource" mean?
i understood so far that closing a stream means that the program can no longer access whatever file it opened.

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abigail Decan wrote:i don't understand what close() does exactly.
i read the API and went to stackflow, but i still can't get a grasp.
for example, what does "releasing the resource" mean?


Perhaps an example might help:
If you need to read or write to a file (which is just one kind of "resource"), the operating system needs to open a 'pointer' of some kind to it. That pointer needs to:
(a) Find the file.
(b) Keep track of any updates that are made to it while you're reading it (operating systems allow lots of users, don't forget).
(b) Track updates that you make to it for other users.
and all of that takes time and space.

Resources therefore tend to be quite "expensive", so anything you can do to help the system release any processes, memory or cache associated with them can help performance. close() simply says "I'm done with this resource, so you don't have to track MY use of it any more".

HIH

Winston
 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- a stream is something that tracks what i'm doing with the resource = file
- this is expensive
- so i want to to enable this so long as i'm actually using the resource
- therefore i close at the end of my session?

thanks for the help
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic