|
Every object that has a Finalize method will be placed on the finalization queue, there is no way to prevent this, and it's not the GC that does that.
What the SuppressFinalize method does is to remove the object from that queue, so that the GC will not place the object in the freachable queue when it's up for collection.
The finalization queue is somewhat misleadingly named, as it's not really a queue at all. It's just a collection of references.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
You mean when SuppressFinalize is called, the object is still put on the finalizer queue, but when finalizer thread runs and checked SuppressFinalize is called already, it will simply remove the object from the queue and reclaim its memory, right?
regards,
George
|
|
|
|
|
I think he meant in other way. Initially all the objects require finalization will be placed into a finalization queue. SuppressFinalize() remove them from the queue, I guess.
|
|
|
|
|
Thanks for clarifying this, I do not know this point before.
regards,
George
|
|
|
|
|
George_George wrote: You mean when SuppressFinalize is called, the object is still put on the finalizer queue, but when finalizer thread runs and checked SuppressFinalize is called already, it will simply remove the object from the queue and reclaim its memory, right?
No, not quite. The effect is bascially the same, but that's not how it works.
I think that you are still confusing the finalizer queue with the freachable queue. The finaliser thread is not finalising object in the finalizer queue, it's finalising objects in the freachable queue.
All objects that have a Finalize method are placed in the finalizer queue when they are created. When the garbage collector finds an object to collect, it will check if it's in the finalizer queue. If it is, it will be placed in the freachable queue, and if it isn't, the memory can simply be reclaimed.
The SuppressFinalize method removes the object from the finalizer queue, so that it will not end up in the freachable queue.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: The finaliser thread is not finalising object in the finalizer queue, it's finalising objects in the freachable queue.
Freachable queue is ReadyForFinalization queue, right ? So objects that have finalization method and not called SuppressFinalize() will be in freachable queue, right ? So objects that don't have finalizers will be in finalization queue ?
BTW, do you know any good tool which shows the heap allocations and memory details ? I tried .NET profiler, and it looks good. Any thoughts ?
|
|
|
|
|
N a v a n e e t h wrote: Freachable queue is ReadyForFinalization queue, right ?
Yes.
N a v a n e e t h wrote: So objects that have finalization method and not called SuppressFinalize() will be in freachable queue, right ?
Yes, when the garbage collector notices that they are up for collection, they will be moved there.
N a v a n e e t h wrote: So objects that don't have finalizers will be in finalization queue ?
No. Objects that do have a Finalizer method will be placed on the finalization queue.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Thanks Guffa,
Your reply is so comprehensive.
regards,
George
|
|
|
|
|
Guffa wrote: and it's not the GC that does that.
Thanks Guffa, but who else will be doing that then ?
|
|
|
|
|
The object is placed on the finalizer queue when it's created, not when it's collected, so it's the code that creates object that does that, not the garbage collector.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
When I implement a finalizer, I ALWAYS use it to show that an object hasn't been disposed of - to my mind, this is it's only real use in our internal code.
|
|
|
|
|
Great reply.
This is not just a "useful answer", and it is not just a five, it is unquantifiable.
I would take off my hat if I had one...
|
|
|
|
|
Luc,
I'll join you, viva la revolution!
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
|
I didn't get it either. Perhaps he's in his own little world.
I agree with your earlier post, that's a great response from Mike Dimmick. I was so impressed I went back and voted!
BDF
A learned fool is more a fool than an ignorant fool.
-- Moliere
|
|
|
|
|
You sig silly :P
I added "I dislike the black-and-white voting system on questions/answers. " to mine too...
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Sorry. I forgot I changed my sig, and I don't read my own sig when I proofread my messages...
Thanks for the support!
BTW: I'm just asking to give back what we had before, that hardly qualifies as a revolution, does it?
|
|
|
|
|
[SpacixOne Goes into hysterical motivational speaking mode]
Did the citizens in Boston sit back and allow the English to force them to drink their nasty over priced tea?
NO! they dressed up as native Americans, to which fooled not even the British, and dumped that team into the harbor!
Did the French sit back and let the Queen tell them to eat cake?
NO! They stood up and said they didn't want to be fat and ugly and killed the Queen and King then hired a short, fat, and ugly evil dictator to take over 90% of Western Europe...
Did the Cubans sit back and wait for Castro to die? (well that's debatable at the moment)
NO! they formed a revolution to take down the commies and were slaughtered and captured in huge numbers! They just wished to make Cuba to be the way it was before the commies took over.
Did the protestors in Tiananmen Square sit back and let the guys in tanks tell them what to do?
NO they stood their ground and were abruptly squashed by those giant tanks.
I tell you sir, that our fight against the oppression by our kind, generous, and caring site builders and administrators by disallowing score votes of 2, 3, and 4 on Questions/Answers is also a Revolution.
In my horrible paraphrased words of Alfred Nobel, "I had not know what I made and seems I just blew it.."
[/SpacixOne Goes into hysterical motivational speaking mode]
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Spacix One wrote: they stood their ground and were abruptly squashed
So I prefer a slightly more subtle approach. Same goals, different means. We will prevail!
|
|
|
|
|
I join you to cheer, Spacix.
regards,
George
|
|
|
|
|
Thanks Mike!
Great!!!!!!
In GC, if gen2 collection is decided to run, then gen2 collection has to wait for gen1 collection complete, and gen1 has to wait for gen0 collection complete?
regards,
George
|
|
|
|
|
Hello everyone,
How could we see the C# compiler expand our code (I mean at source code level, not using ILDasm to see at IL level or using Diassembly at native assembly code level)?
For example, this is how foreach is expanded in C#.
http://www.csharpfriends.com/Spec/index.aspx?specID=15.8.4.htm
thanks in advance,
George
|
|
|
|
|
One way would be to write simple code, then use Reflector[^] to browse the resultant code.
The using statement is the other one that is just some syntactic sugar, it just builds code you could write just as easily, although I think it's a cool thing to use it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|