finalizer

Is it safe to call an RCW from a finalizer?

南楼画角 提交于 2019-11-27 12:49:43
I have a managed object that calls a COM server to allocate some memory. The managed object must call the COM server again to free that memory before the managed object goes away to avoid a memory leak. This object implements IDisposable to help ensure that the correct memory-releasing COM call is made. In the event that the Dispose method is not called, I would like the object's finalizer to free the memory. The trouble is, the rules of finalization is that you must not access any reference because you don't know what other objects have already been GC'd and/or finalized before you. This

Xamarin Android Finalizer not getting called when leaving the activity to go to another Activity

大憨熊 提交于 2019-11-27 12:31:28
The Finalizer is never called after leaving the activity. Does that mean the activity is still alive even though I moved on to the next activity. namespace XamarinTest { [Activity(Label = "XamarinTest", Icon = "@drawable/icon")] public class MainActivity : Activity { private int count = 1; private TextView density; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.ScreenData); density = FindViewById<TextView>(Resource.Id.Density); var pendingInent = new Intent(); pendingInent.SetFlags

Static Finalizer

[亡魂溺海] 提交于 2019-11-27 05:24:18
问题 What is the right way to perform some static finallization? There is no static destructor. The AppDomain.DomainUnload event is not raised in the default domain. The AppDomain.ProcessExit event shares the total time of the three seconds (default settings) between all event handlers, so it's not really usable. 回答1: Basically, you can't. Design your way around it to the fullest extent possible. Don't forget that a program can always terminate abruptly anyway - someone pulling out the power being

Are .net finalizers always executed?

一曲冷凌霜 提交于 2019-11-27 04:24:41
Are finalizers guaranteed to be executed in .NET at some point (spare power outages and the like)? I know how GC works and that it is nondeterministic when exactly they'll run. (The search did not display good answers, so I'm adding this question in high expectation of a merge with the not-so-easy-to-discover actual answers. Apart from that, I already know the answer and am going to add it after a few days in case nobody mentioned it.) Finalizers may actually be never executed, as Raymond Chen explains . Kind of funny that this question is asked during his annual CLR week, just two days after

Why structs cannot have destructors?

ぃ、小莉子 提交于 2019-11-27 02:33:43
问题 What is best answer on interview on such question you think? I think I didn't find a copy of this here, if there is one please link it. 回答1: Another way of looking at this - rather than just quoting the spec which says that structs can't/don't have destructors - consider what would happen if the spec was changed so that they did - or rather, let's ask the question: can we guess why did the language designers decide to not allow structs to have 'destructors' in the first place? (Don't get hung

The difference between a destructor and a finalizer?

北城余情 提交于 2019-11-27 01:34:34
问题 Please Note: This question is about the difference in terminology between the words "destructor" and "finalizer" and their correct usage. I have merely provided examples of their use in C# and C++/CLI to demonstrate why I am asking the question. I am well aware of how it is implemented in both C# and the CLR, but I am asking about the correct use of terminology. In the C# world the terms "destructor" and "finalizer" seem to be used pretty much interchangeably, which I suspect is because the C

Reference to object during finalize

自作多情 提交于 2019-11-26 22:15:03
问题 What happens if you save a reference to the current object during the finalize call? For example: class foo { ... public void finalize() { bar.REFERENCE = this; } } Is the object garbage-collected, or not? What happens when you try to access bar.REFERENCE later? 回答1: The object is not garbage collected. This is know as "Object resurrection". You must be careful with that, once the finalizer is called the gc won't call it again, on some enviroments like .NET you can re-register the finalizer

Release Excel Object In My Destructor

自古美人都是妖i 提交于 2019-11-26 21:04:33
问题 I'm writing a Excel class using Microsoft.Interropt.Excel DLL. I finish all function but I have an error in my Destructor. I Want to save all changes to my file and I want to release all source. I want to all of them in my destructor. But In my destructor, Excel.ApplicationClass, Workbook and Worksheet objects are fill by an Exception which have message "COM object that has been separated from its underlying RCW cannot be used." So I can't save nothing, close nothing because ı can't access

GC.Collect() and Finalize

☆樱花仙子☆ 提交于 2019-11-26 19:58:56
问题 Ok, it's known that GC implicitly calls Finalize methods on objects when it identifies that object as garbage. But what happens if I do a GC.Collect() ? Are the finalizers still executed? A stupid question maybe, but someone asked me this and I answered a "Yes" and then I thought: " Was that fully correct? " 回答1: Ok, it's known that GC implicitly calls Finalize methods on objects when it identifies that object as garbage. No no no. That is not known because in order to be knowledge a

is memory leak? why java.lang.ref.Finalizer eat so much memory

为君一笑 提交于 2019-11-26 18:47:06
I ran a heap dump on my program. When I opened it in the memory analyzer tool, I found that the java.lang.ref.Finalizer for org.logicalcobwebs.proxool.ProxyStatement was taking up a lot of memory. Why is this so? Peter Lawrey Some classes implement the Object.finalize() method. Objects which override this method need to called by a background thread call finalizer, and they can't be cleaned up until this happens. If these tasks are short and you don't discard many of these it all works well. However if you are creating lots of these objects and/or their finalizers take a long time, the queue