How to find which Finalizer takes time

I am working on an application whose purpose is to compute reports has fast as possible. My application uses a big amount of memory; more than 100 Go. Since our last release, I notice a big performance slowdown. My investigation shows that, during th

Cleaning a .net WeakReferences cache

In my application, I have a Dictionary<int, WeakReference<Foo>> to cache Foos read from a file, where the key is the index in the file. Since the Foos are mutable, a cache entry must remain alive as long as any reference to the Foo at that ind

Java equivalent of GC.SuppressFinalize

Does Java have an equivalent of .Net's GC.SuppressFinalize? In .Net, SuppressFinalize is used in the dispose pattern to avoid the relatively high performance cost of finalization as long as the object is explicitly disposed. Similar costs apply to Ja

Java does not release objects with the finalize () parameter

My application makes use of a third-party library (the JTDS driver) that has some objects that override the finalize() method. I think they obey all the rules about when not to use finalize() - it doesn't depend on them running in a timely manner or

method of stopping and finalizing

I just fail to understand why must one use Runtime.addShutdownHook. If you want to do some cleanup when the jvm exits, why not just overload the finalize method of the daemon class. What is the advantage of using shutdown hook over finalize method. A

Use finalize () in my case?

I have an ImageWrapper class that saves images to temporary files in disk in order to free heap memory, and allows reloading them when needed. class ImageWrapper { File tempFile; public ImageWrapper(BufferedImage img) { // save image to tempFile and

Arrange safely in .net finalizer

I wanted a way to break the IDisposable chain where some nested class that you suddenly depend on now implements IDisposable and you don't want that interface to ripple up the layers of your composite. Basically, I have weak subscriptions to IObserva

Garbage collection in C #; have objects in a specific thread

To learn C# native interop, I've been working on an OpenGL wrapper. The OpenGL API itself is a state machine which is bound to a specific thread. When an object containing native resources is garbage collected, the finalizer is running in the GC thre

Why NET garbage collector is never called?

I'am working on an application that has problems with its memory consumption. If a user clicks long enough in the application it ends in an OutOfMemoryException. I profiled the application with 'ANTS Memory Profiler' quite a long time and in my opini

GC.Collect () does not collect immediately?

In the course of a discussion in chat, I wrote this console application. Code: using System; class Program { static void Main(string[] args) { CreateClass(); Console.Write("Collecting... "); GC.Collect(); Console.WriteLine("Done"); } s

Calling Dispose Method Will Erase and Compact Memory in .Net?

I have idea about Dispose and Finalize method in .Net as following. Please correct me if I am wrong. Dispose : Implement IDisposable inferface and remove unused/unmanaged code in Dispose method. Developer needs to call it manually if they want immedi

How to call arrange on a custom trace listener in C #

I have written a custom trace listener extending TextWriterTraceListener. Now, how do I call the Dispose() on the listener? I add it through the app.config of my project. Tried adding the call Dispose(false) in the finalizer, but it not being called.

Garbage collection and finalizers: finer points

In answering another question on SO, and the subsequent comment discussion, I ran into a wall on a point that I'm not clear on. Correct me on any point where I'm astray... When the Garbage Collector collects an object, it calls that object's finalize

Performance penalty for Finalizer if ever called

I have a class with a finalizer. But since I'm always calling Dispose() and Dispose() is calling GC.SupressFinalize(this), I think my object never actually makes it into the finalization queue. The finalizer is just in there as a backstop in case ano

Two questions about Dispose () and the destructors in C #

I have a question about how to use Dispose() and destructors. Reading some articles and the MSDN documentation, this seems to be the recommended way of implementing Dispose() and destructors. But I have two questions about this implementation, that y

Good examples of using Finalizers in C #

When I read a few articles about memory management in C#, I was confused by Finalizer methods. There are so many complicated rules which related with them. For instance, nobody knows when the finalizers will be called, they called even if code in cto

Use Dispose () or the finalizer to clean up managed threads?

Suppose I have a message pump class in C++0x like the following (note, SynchronizedQueue is a queue of function<void()> and when you call receive() on the queue and it is empty, it blocks the calling thread until there is an item to return): class M

java: wait (), notify () and synchronized blocks

I learned that calling an Object's wait() method will release the object monitor, if present. But I have some questions regarding calling notify() on this object by another thread: (when) will the waiting thread wake up, if another (a 3rd) thread own

How can I test a finalizer?

I have the following class which is a decorator for an IDisposable object (I have omitted the stuff it adds) which itself implements IDisposable using a common pattern: public class DisposableDecorator : IDisposable { private readonly IDisposable _in

Implement Dispose or Finalize?

Class ComponentsContainer ' a component contains other components' Inherits System.ComponentModel.Component Private foo as New Component Private bar as New Component Protected Override Sub Finalize() foo.Dispose() ' HERE ? ' bar.Dispose() MyBase.Fina

Is it safe to call a RCW from a finalizer?

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 ensu

Correct cleaning of WPF user controls

I am relatively new to WPF, and some things with it are quite foreign to me. For one, unlike Windows Forms, the WPF control hierarchy does not support IDisposable. In Windows Forms, if a user control used any managed resources, it was very easy to cl

DataGridViewRow is not recovered Garbage

I have a DataGridView being regularly populated via data-bound objects, and the number of rows can potentially become large, say many thousands during a 'logging cycle'. When a new 'logging cycle' begins, the grid is cleared because the underlying da

.NET - Finalists and exit (0)

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 c