Click here to Skip to main content
15,887,135 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Controlling session time in WinForms app - best approach? Pin
nzmike12-Dec-06 20:20
nzmike12-Dec-06 20:20 
QuestionFinalize method Pin
rockyl12-Dec-06 3:04
rockyl12-Dec-06 3:04 
AnswerRe: Finalize method Pin
Rob Graham12-Dec-06 3:13
Rob Graham12-Dec-06 3:13 
GeneralRe: Finalize method Pin
rockyl12-Dec-06 3:44
rockyl12-Dec-06 3:44 
GeneralRe: Finalize method Pin
Rob Graham12-Dec-06 7:57
Rob Graham12-Dec-06 7:57 
GeneralRe: Finalize method Pin
rockyl12-Dec-06 17:12
rockyl12-Dec-06 17:12 
GeneralRe: Finalize method Pin
User 58385212-Dec-06 12:03
User 58385212-Dec-06 12:03 
AnswerRe: Finalize method Pin
Guffa13-Dec-06 2:59
Guffa13-Dec-06 2:59 
Josh Gray wrote:
I read this article[^] and it seemed to suggest that a finaliser is required as a back up in case the person using your class does not call Dispose() when they are finished with the object.


That is correct. The preferred method of handling objects that uses unmanaged resources is to call the Dispose method. That way the programmer can control when the resources are being freed.

The finalizer is called by the garbage collector when the object is collected, if the Dispose method has not been called. The problem with this is that you can not predict when this will happen, and there isn't even any guarantee that the finalizer will ever be called. If there are a lot of objects in the finalizer queue when the program ends, it's not certain that all of them will be handled before the system decides that it takes too long to finalize all the objects, and just kills off the rest.

Josh Gray wrote:
For example, if I have a class A that has a reference to another dot net class B and attaches to events on B in the constructor where do I unattach from the event? If I put it in a Dispose() method and the user of the class does not call Dispose() on it what happens? The article above seemed to suggest that I should implement a Finalizer to handle this case


It's good to have a finalizer as a fallback. That way the object will be disposed eventually (at least in most cases) if the programmer fails to call Dispose properly.

---
It's amazing to see how much work some people will go through just to avoid a little bit of work.

GeneralRe: Finalize method Pin
Scott Dorman13-Dec-06 3:42
professionalScott Dorman13-Dec-06 3:42 
AnswerRe: Finalize method Pin
Guffa13-Dec-06 3:09
Guffa13-Dec-06 3:09 
GeneralRe: Finalize method Pin
Scott Dorman13-Dec-06 3:45
professionalScott Dorman13-Dec-06 3:45 
GeneralRe: Finalize method Pin
Guffa13-Dec-06 4:01
Guffa13-Dec-06 4:01 
GeneralRe: Finalize method Pin
Scott Dorman13-Dec-06 4:26
professionalScott Dorman13-Dec-06 4:26 
GeneralRe: Finalize method Pin
Guffa13-Dec-06 4:36
Guffa13-Dec-06 4:36 
GeneralRe: Finalize method Pin
karam chandrabose13-Dec-06 5:29
karam chandrabose13-Dec-06 5:29 
AnswerRe: Finalize method Pin
Guffa13-Dec-06 5:56
Guffa13-Dec-06 5:56 
QuestionImage Problem Pin
Tauseef A12-Dec-06 2:16
Tauseef A12-Dec-06 2:16 
AnswerRe: Image Problem Pin
Paul Conrad26-Dec-06 17:08
professionalPaul Conrad26-Dec-06 17:08 
QuestionWeb service Authentication Pin
Nithin Krishna12-Dec-06 0:28
Nithin Krishna12-Dec-06 0:28 
QuestionWither windows service? Pin
PhrankBooth11-Dec-06 16:05
PhrankBooth11-Dec-06 16:05 
QuestionVSTO for Outlook 2007 Pin
Felix Jongleur11-Dec-06 12:17
Felix Jongleur11-Dec-06 12:17 
QuestionVisual Studio Tools for Office version 2003 Pin
ocabrera7011-Dec-06 3:00
ocabrera7011-Dec-06 3:00 
QuestionModifying machine.config Pin
seanwright11-Dec-06 2:56
seanwright11-Dec-06 2:56 
AnswerRe: Modifying machine.config Pin
Pete O'Hanlon11-Dec-06 10:22
mvePete O'Hanlon11-Dec-06 10:22 
AnswerRe: Modifying machine.config Pin
Vasudevan Deepak Kumar12-Dec-06 3:22
Vasudevan Deepak Kumar12-Dec-06 3:22 

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.