Click here to Skip to main content
16,008,299 members
Home / Discussions / C#
   

C#

 
GeneralRe: Unable to fill certain fields inside the DOM of some websites! Pin
alon198021-Apr-08 4:36
alon198021-Apr-08 4:36 
GeneralFinalizer implementation Pin
George_George19-Apr-08 21:20
George_George19-Apr-08 21:20 
GeneralRe: Finalizer implementation Pin
Scott Dorman20-Apr-08 4:57
professionalScott Dorman20-Apr-08 4:57 
GeneralRe: Finalizer implementation Pin
carbon_golem20-Apr-08 5:29
carbon_golem20-Apr-08 5:29 
GeneralRe: Finalizer implementation Pin
George_George20-Apr-08 17:38
George_George20-Apr-08 17:38 
GeneralRe: Finalizer implementation Pin
carbon_golem21-Apr-08 1:53
carbon_golem21-Apr-08 1:53 
GeneralRe: Finalizer implementation Pin
George_George21-Apr-08 2:07
George_George21-Apr-08 2:07 
GeneralRe: Finalizer implementation Pin
carbon_golem21-Apr-08 6:32
carbon_golem21-Apr-08 6:32 
That's right. The garbage collection can't guarantee that anything will be available - think of the case that your finalizer is the absolute last thing that is done in your application before it shuts down, all other resources have been reclaimed including all the members inside your class. That's what you have to deal with. The purpose of a finalizer is to give you one last chance to free any native resources that your class may use. One case is that you decide that you want a class with a Hook created by CreateWindowsHookEx and you own that hook. Finalizer implementation would be advised because you are using a native resource directly, and you don't want to leak that resource. As long as the finalizer exists, the runtime will call it, you don't need to. One special case is when you release the resource in your Dispose method, at then end of the Dispose, make a call to GC.SupressFinalize and the finalizer won't get called. Getting the idea?

If your class is using a built in .NET class that owns native resources, you can be pretty sure that .NET takes care of the finalizer for you. IF you implement a finalizer, the runtime calls it. The same holds true for the finalizers that .NET is using. Oh, one last thing, if you do decide to use a native resource by handle, look into .NET's SafeHandle classes, and that will shed some insight on what you're doing.

Again
1) If you implement a finalizer, the runtime will call it when it's being reclaimed by the garbage collector - UNLESS you have explicitly made a call to GC.SupressFinalize.
2) Implement a finalizer when you are using Native Resources, notably Handles.
3) You can never be sure what other data will be available when your finalizer is called.
4) Get Lutz's Reflector, and see how .NET does it's finalizers. I won't answer questions about Reflector, stfw. Smile | :)

Scott P

"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand

GeneralRe: Finalizer implementation Pin
George_George21-Apr-08 21:49
George_George21-Apr-08 21:49 
GeneralRe: Finalizer implementation Pin
carbon_golem22-Apr-08 2:39
carbon_golem22-Apr-08 2:39 
GeneralRe: Finalizer implementation Pin
George_George22-Apr-08 3:04
George_George22-Apr-08 3:04 
GeneralRe: Finalizer implementation Pin
George_George20-Apr-08 19:02
George_George20-Apr-08 19:02 
GeneralRe: Finalizer implementation Pin
Scott Dorman22-Apr-08 17:13
professionalScott Dorman22-Apr-08 17:13 
GeneralRe: Finalizer implementation Pin
George_George22-Apr-08 17:20
George_George22-Apr-08 17:20 
GeneralRe: Finalizer implementation Pin
Scott Dorman22-Apr-08 17:36
professionalScott Dorman22-Apr-08 17:36 
GeneralRe: Finalizer implementation Pin
George_George22-Apr-08 17:47
George_George22-Apr-08 17:47 
GeneralRe: Finalizer implementation Pin
Scott Dorman23-Apr-08 2:15
professionalScott Dorman23-Apr-08 2:15 
GeneralRe: Finalizer implementation Pin
George_George23-Apr-08 2:49
George_George23-Apr-08 2:49 
Generalroot in managed heap Pin
George_George19-Apr-08 21:01
George_George19-Apr-08 21:01 
GeneralRe: root in managed heap Pin
Gareth H19-Apr-08 23:15
Gareth H19-Apr-08 23:15 
GeneralRe: root in managed heap Pin
George_George19-Apr-08 23:21
George_George19-Apr-08 23:21 
GeneralRe: root in managed heap Pin
Jordanwb20-Apr-08 4:06
Jordanwb20-Apr-08 4:06 
GeneralRe: root in managed heap Pin
Luc Pattyn20-Apr-08 2:37
sitebuilderLuc Pattyn20-Apr-08 2:37 
GeneralRe: root in managed heap Pin
George_George20-Apr-08 3:16
George_George20-Apr-08 3:16 
GeneralRe: root in managed heap Pin
Luc Pattyn20-Apr-08 3:38
sitebuilderLuc Pattyn20-Apr-08 3:38 

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.