Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C#
This is the forum to discuss the Wrox book MCSD Certification Toolkit (Exam 70-483): Programming in C# by Tiberiu Covaci, Rod Stephens, Vincent Varallo, Gerry O'Brien; ISBN: 978-1-118-61209-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 31st, 2019, 01:02 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2019
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Managing Object Life Cycle

The Dispose method
  #2 (permalink)  
Old May 31st, 2019, 01:11 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2019
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5

Question1:
The Dispose method
  #3 (permalink)  
Old May 31st, 2019, 07:09 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Quote:
The Dispose method’s main purpose is to clean up unmanaged resources, but it can also clean up managed resources.

If the class has only managed resources, it should implement IDisposable but it doesn’t need a destructor.

Question is why we "should" implement IDisposable. Garbage collector cleans up managed resources. Maybe for immediate cleanup?
Exactly. The garbage collector will eventually get around to cleaning up managed resources, but you don't know long that may take.

For an example, suppose an object opens and locks a file, and then the program stops using that object. The file may remain open and locked. Eventually the garbage collector will destroy the file stream, but other programs may want to use the file in the meantime. For instance, you might want to use File Explorer to delete it. In fact, other parts of the same program might want to use or delete the file.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)

Last edited by Rod Stephens; June 3rd, 2019 at 10:52 AM..


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 page 52-53 Activity Life cycle herbchess BOOK: Beginning Android Programming with Android Studio, Fourth Edition 0 January 16th, 2018 02:58 PM
Null or Cycle Entertainment Unit BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 3rd Edition 1 December 22nd, 2014 05:59 PM
Here is Practical Explanation about Next Life, Purpose of Human Life - alex.o RSS and Atom 0 November 22nd, 2014 01:33 PM
Tomcat life cycle listener dp_java Apache Tomcat 0 August 21st, 2006 06:39 AM
Simplify your life with Object Binding sarosh .NET Framework 2.0 0 March 31st, 2006 01:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.