finalizer

.NET - Finalizers and exit(0)

♀尐吖头ヾ 提交于 2019-12-01 08:40:28
I have a .NET C# / C++ app which uses a call to exit(0) (from <stdlib.h> ) in a thread in order to terminate. The strange part is, under some circumstances, the finalizers of the managed objects are called right after the call to exit , and in other circumstances, they are not called at all. The circumstances are pretty deterministic - the app calls some methods from an external plugin dll (written in unmanaged C) during its lifetime. If I use dll A, the finalizers are always called. If I use dll B, the finalizers are never called. What's the expected behaviour of finalizers in case of an exit

.NET - Finalizers and exit(0)

廉价感情. 提交于 2019-12-01 06:13:48
问题 I have a .NET C# / C++ app which uses a call to exit(0) (from <stdlib.h> ) in a thread in order to terminate. The strange part is, under some circumstances, the finalizers of the managed objects are called right after the call to exit , and in other circumstances, they are not called at all. The circumstances are pretty deterministic - the app calls some methods from an external plugin dll (written in unmanaged C) during its lifetime. If I use dll A, the finalizers are always called. If I use

Deleting an object in Ruby

久未见 提交于 2019-12-01 02:13:52
Let's say I have the following class: class Vehicle @@total_vehicles = 0 @@all_instances = Array.new def initialize @@total_vehicles += 1 @@all_instances << self end def total_vehicles #returns total number of Vehicles 'alive' return @@total_vehicles end def all_vehicles #returns an array of all Vehicle objects return @@all_instances end end Now to keep @@total_vehicles and @@all_instances up-to-date and correct, I want to make sure that they are correctly decremented and updated, respectively, when one of those objects is garbage collected. But here is what happens: v = Vehicle.new Vehicle

When GC.KeepAlive(this) is needed when doing P/Invoke on unmanaged resources?

不想你离开。 提交于 2019-12-01 01:18:19
I have a TestNet wrapper for a native component. The native component exposes a blocking TestNative::Foo() that communicates with managed part through calling managed callbacks and a weak GCHandle that is used to retrieve the reference to the .NET wrapper and provides a context. The GCHandle is weak since the .NET wrapper is meant to hide the fact that is handling unmanaged resources to user and deliberately doesn't implement the IDisposable interface: being non weak it would prevent TestNet instances from being collected at all, creating a memory leak. What's happening is that in Release

Finalizers with Dispose() in C#

会有一股神秘感。 提交于 2019-11-30 22:16:29
See the code sample from MSDN: ( http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx ) // Design pattern for a base class. public class Base: IDisposable { private bool disposed = false; //Implement IDisposable. public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // Free other state (managed objects). } // Free your own state (unmanaged objects). // Set large fields to null. disposed = true; } } // Use C# destructor syntax for finalization code. ~Base() { // Simply call Dispose(false)

Deleting an object in Ruby

笑着哭i 提交于 2019-11-30 21:00:46
问题 Let's say I have the following class: class Vehicle @@total_vehicles = 0 @@all_instances = Array.new def initialize @@total_vehicles += 1 @@all_instances << self end def total_vehicles #returns total number of Vehicles 'alive' return @@total_vehicles end def all_vehicles #returns an array of all Vehicle objects return @@all_instances end end Now to keep @@total_vehicles and @@all_instances up-to-date and correct, I want to make sure that they are correctly decremented and updated,

(.net) CriticalFinalizerObject - What does it really do?

一笑奈何 提交于 2019-11-30 20:56:02
My understanding about this class is that you should use it when you want to be sure that the Finalizer(destructor) or the class is called, but from a couple of tests I did, it doesn't seem to be true. If it does not make sure that the dispose method is called, is there any other way of doing it? For example, if i want to make sure that some code is run to end my object, even if I close my program via Task Manager or something? Chris Brumme has explained this topic in a way I'm not sure could ever be topped. :) from a couple of tests I did, it doesn't seem to be true. Finalizers in .Net are

When GC.KeepAlive(this) is needed when doing P/Invoke on unmanaged resources?

谁说胖子不能爱 提交于 2019-11-30 20:37:20
问题 I have a TestNet wrapper for a native component. The native component exposes a blocking TestNative::Foo() that communicates with managed part through calling managed callbacks and a weak GCHandle that is used to retrieve the reference to the .NET wrapper and provides a context. The GCHandle is weak since the .NET wrapper is meant to hide the fact that is handling unmanaged resources to user and deliberately doesn't implement the IDisposable interface: being non weak it would prevent TestNet

Performance implications of finalizers on JVM

亡梦爱人 提交于 2019-11-30 20:35:16
According to this post , in .Net, Finalizers are actually even worse than that. Besides that they run late (which is indeed a serious problem for many kinds of resources), they are also less powerful because they can only perform a subset of the operations allowed in a destructor (e.g., a finalizer cannot reliably use other objects, whereas a destructor can), and even when writing in that subset finalizers are extremely difficult to write correctly. And collecting finalizable objects is expensive: Each finalizable object, and the potentially huge graph of objects reachable from it, is promoted

Finalizers with Dispose() in C#

社会主义新天地 提交于 2019-11-30 18:26:35
问题 See the code sample from MSDN: (http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx) // Design pattern for a base class. public class Base: IDisposable { private bool disposed = false; //Implement IDisposable. public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // Free other state (managed objects). } // Free your own state (unmanaged objects). // Set large fields to null. disposed =