Click here to Skip to main content
15,913,944 members
Home / Discussions / C#
   

C#

 
GeneralRe: Pattern Matching in C# [modified] Pin
KKrista4-Jun-07 21:34
KKrista4-Jun-07 21:34 
GeneralRe: Pattern Matching in C# Pin
Christian Graus4-Jun-07 22:29
protectorChristian Graus4-Jun-07 22:29 
GeneralRe: Pattern Matching in C# Pin
M. J. Jaya Chitra4-Jun-07 22:51
M. J. Jaya Chitra4-Jun-07 22:51 
GeneralRe: Pattern Matching in C# Pin
Christian Graus4-Jun-07 23:00
protectorChristian Graus4-Jun-07 23:00 
GeneralThank you Pin
M. J. Jaya Chitra4-Jun-07 23:09
M. J. Jaya Chitra4-Jun-07 23:09 
QuestionDispose pattern [modified] Pin
cateyes994-Jun-07 20:29
cateyes994-Jun-07 20:29 
AnswerRe: Dispose pattern Pin
Christian Graus4-Jun-07 20:52
protectorChristian Graus4-Jun-07 20:52 
AnswerRe: Dispose pattern Pin
S. Senthil Kumar5-Jun-07 4:57
S. Senthil Kumar5-Jun-07 4:57 
cateyes_99 wrote:
Setting the references to nothing doesn't mean that, it just tells .Net that we don't need them any more, they can be recollected from this point of time.


But what about other managed objects that wrap unmanaged resources. Things like File, Pen etc.? For example :-
class TheDisposable : IDisposable
{
   IntPtr handle;    //Direct unmanaged resource
   FileStream stream;//Managed but wraps an unmanaged resource

   public void Dispose
   {
      Dispose(true);
      GC.SuppressFinalize(this);
   }

   protected virtual void Dispose(bool disposing)
   {
      if (disposing)
      {
         stream.Dispose();
      }
      CloseHandle(handle);
   }

   ~TheDisposable() { Dispose(false); }
}

If you don't explicitly dispose the stream here, you'd have to wait for the finalizer for that particular FileStream object to run (assuming it has a finalizer).

Like you said, there is no need (usually) to set references to null in Dispose, as the GC is intelligent enough to figure out that an object has no live references.

Regards
Senthil [MVP - Visual C#]
_____________________________
My Blog | My Articles | My Flickr | WinMacro

GeneralRe: Dispose pattern Pin
cateyes995-Jun-07 11:17
cateyes995-Jun-07 11:17 
Generalsms.ud = work.msg.Content Pin
abdulsamad.shaik4-Jun-07 19:55
abdulsamad.shaik4-Jun-07 19:55 
GeneralRe: sms.ud = work.msg.Content Pin
Christian Graus4-Jun-07 20:53
protectorChristian Graus4-Jun-07 20:53 
AnswerRe: sms.ud = work.msg.Content Pin
Muammar©4-Jun-07 20:58
Muammar©4-Jun-07 20:58 
Questionretreive the name of the image Pin
dinosors4-Jun-07 19:50
dinosors4-Jun-07 19:50 
AnswerRe: retreive the name of the image Pin
Christian Graus4-Jun-07 20:53
protectorChristian Graus4-Jun-07 20:53 
AnswerRe: retreive the name of the image Pin
Luc Pattyn5-Jun-07 0:55
sitebuilderLuc Pattyn5-Jun-07 0:55 
QuestionPanel Manip (Simple but a great head ache) Pin
M. J. Jaya Chitra4-Jun-07 19:15
M. J. Jaya Chitra4-Jun-07 19:15 
AnswerRe: Panel Manip (Simple but a great head ache) Pin
Christian Graus4-Jun-07 20:54
protectorChristian Graus4-Jun-07 20:54 
GeneralThank you Pin
M. J. Jaya Chitra4-Jun-07 22:46
M. J. Jaya Chitra4-Jun-07 22:46 
QuestionVC++ to C# Pin
Kabirdas Jaunjare4-Jun-07 17:45
Kabirdas Jaunjare4-Jun-07 17:45 
AnswerRe: VC++ to C# Pin
Christian Graus4-Jun-07 20:55
protectorChristian Graus4-Jun-07 20:55 
QuestionTaking Urdu Text Input in a dataGridView or a TextBox Pin
Rocky#4-Jun-07 14:51
Rocky#4-Jun-07 14:51 
AnswerRe: Taking Urdu Text Input in a dataGridView or a TextBox Pin
Nouman Bhatti5-Jun-07 1:56
Nouman Bhatti5-Jun-07 1:56 
GeneralRe: Taking Urdu Text Input in a dataGridView or a TextBox Pin
Rocky#5-Jun-07 5:09
Rocky#5-Jun-07 5:09 
GeneralRe: Taking Urdu Text Input in a dataGridView or a TextBox Pin
Nouman Bhatti5-Jun-07 8:43
Nouman Bhatti5-Jun-07 8:43 
GeneralRe: Taking Urdu Text Input in a dataGridView or a TextBox Pin
Rocky#5-Jun-07 19:31
Rocky#5-Jun-07 19:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.