Questions tagged [finalizer]

A finalizer is a special method in an object-oriented language that is executed when an object is garbage collected.

A finalizer is a special method in an object-oriented language that is executed when an object is garbage collected.

Java Documentation (Javadoc) defines the moment when the finalizer is invoked as:

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

However, this may never happen in the life of a program if the object is always accessible. Due to the lack of programmer control over their execution, it is usually recommended to avoid finalizers for any but the most trivial operations.

442 questions
0
votes
1 answer

Can I safely track unmanaged resources with a managed List?

Let's say I have a disposable class which uses a List to keep track of unmanaged resources: public class MyDisposableClass : IDisposable { private readonly List _myUnmanagedResources = new List(); …
BTownTKD
  • 7,911
  • 2
  • 31
  • 47
0
votes
2 answers

finalizer guardian didn't run

My finalizer guardian failed to run by the time my program exited. Here he is: public class SomeClass implements SomeInterface { ... setup the PrintWriter os somewhere here /** oh, i guess i wanted to try out finalizer guardians here. */ …
bharal
  • 15,461
  • 36
  • 117
  • 195
0
votes
3 answers

Check that a method is called before object is collected

I have an object that user typically creates using my factory. I want to make sure my user calls object.undo() before they throw it into the garbage collector. This class setups the necessary resources so the user isn't writing to production…
Dat Chu
  • 10,822
  • 13
  • 58
  • 82
0
votes
1 answer

How to release control out of memory before application shuts down?

I have a very bad performance issue. I´m currently working on a multi-window application, but when I close one of the windows no memory is deallocated. There are even controls I instantiate in code and after I used them I assigned null to their…
christoph
  • 1,019
  • 1
  • 12
  • 23
0
votes
2 answers

Java finalize() call counting

I want to count how many times garbage collector call my finalize method, but i don't know how to implement global variable to do this. I've tried this way: class ObjMaker { int obj_nr; ObjMaker(int obj_nr){ this.obj_nr = obj_nr; …
v008.1
  • 3
  • 2
0
votes
1 answer

Block IDisposable.Dispose from thread-safe methods

I'm working with a class that manages a game's content and I'd like to know how I'm able to block calls to the dispose method without locking onto a shared dispose-lock? The worker methods themselves are thread-safe and can be executed in parallel,…
Moritz Gunz
  • 702
  • 6
  • 15
0
votes
6 answers

Where does call to finalizer really go

Now, I wrote a simple code. public class ToDo { ToDo instance; public ToDo () { } void foo() { System.out.println("foo."); } void bar() { System.out.println("bar."); } public static void…
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
0
votes
1 answer

Can a Finalizer use a string member?

I have code like this: ~MyClass() { try { if (Database.Exists(_connectionString)) { Database.Delete(_connectionString); } } catch { } } Database is a static class of Entity Framework, whereas…
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
0
votes
0 answers

How do I detect which of my hundreds of thousands of objects is throwing an exception in the finalizer?

When our application exits normally, on a 64 bit platform there is no exception. On a 32bit platform we get this very unhelpful exception that shows as a system error on Windows XP: InvalidOperationException: Handle is not initialized. at…
Berin Loritsch
  • 11,400
  • 4
  • 30
  • 57
0
votes
5 answers

Object.Finalize() override and GC.Collect()

I cannot seem to understand the behavior of GC.Collect() under the presence of a class overriding Object.Finalize(). This is my base code: namespace test { class Foo { ~Foo() { Console.WriteLine("Inside Foo.Finalize()"); } } static class…
Alexandre Bell
  • 3,141
  • 3
  • 30
  • 43
0
votes
1 answer

Mule - flow cleanup code approach

We just started using Mule a month back and so far it's been a good learning. Right now, we have quite a few flows implemented that integrates our disparate systems. One of the requirements for us is to execute at the end of each flow some clean-up…
Arun
  • 1
0
votes
2 answers

About the Dispose pattern and the Finalizer in C#

First in this MSDN page there is a standard Dispose pattern. And there is a bool as the parameter of the protected Dispose method to tell the GC whether managed resources are freed manually already, so that the GC does not need to care about them.…
Weixiang Guan
  • 457
  • 2
  • 6
  • 16
0
votes
1 answer

Can a C# class automatically manage unamanaged resources

I'm wrapping some native code that has some manual resource handling. I want my C# wrapper to handle this without passing the responsibility on to the clients. Is this possible, or will I inevitably have to implement IDisposable and pass on the…
Tom Davies
  • 2,386
  • 3
  • 27
  • 44
0
votes
1 answer

Cache to map IntPtr handles to C# class instances in pinvoke callbacks

I'm writing a C# wrapper around a native dll that uses opaque pointers to identify resources. A typical example would be something like typedef struct session session; typedef struct track track; void* sessionCreate(int arg, session** sess); void …
Tom Davies
  • 2,386
  • 3
  • 27
  • 44
0
votes
3 answers

is finalizers guaranteed to be called in Java?

Is finalizers guaranteed to be called in Java? If it differs from JVM to JVM, what about the case in Dalvik VM for Android?
dacongy
  • 2,504
  • 3
  • 30
  • 48
1 2 3
29
30