• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is closing?  RSS feed

 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!