Wrox Programmer Forums
|
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
 
Old May 31st, 2019, 01:02 PM
Registered User
 
Join Date: May 2019
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Managing Object Life Cycle

The Dispose method
 
Old May 31st, 2019, 01:11 PM
Registered User
 
Join Date: May 2019
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5

Question1:
The Dispose method
 
Old May 31st, 2019, 07:09 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
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.