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
2 answers

What does it mean for an object to be "finalizer-reachable" in Java?

I am reading the Java 8 spec and I see this definition for finalizer-reachable: A finalizer-reachable object can be reached from some finalizable object through some chain of references, but not from any live thread. What would this look like in…
Andrew
  • 6,295
  • 11
  • 56
  • 95
0
votes
0 answers

How To Debug Override finalize() Method In Java?

As we know about this like... The java.lang.Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to …
0
votes
3 answers

If an object's finalizer has been called, can I be 100% sure that it is/will be removed from memory afterwards?

I have a WPF application that allows the user to open, close and reopen an arbitrary amount of child windows. Using VS2015's integrated memory profiler I found out that a certain type of child window, let's call it ProblematicChildWindow, always…
Golvellius
  • 1,928
  • 2
  • 13
  • 16
0
votes
1 answer

InvalidComObjectException when using Excel Interop

I get an InvalidComObjectException after I close my application in the following piece of code: class MyExcelManager { myExelAppInstance = new Excel.Application(); // finalizer ~MyExcelManager() { myExelAppInstance.Quit(); //…
codymanix
  • 28,510
  • 21
  • 92
  • 151
0
votes
1 answer

How GC manages any class/object like streamwriter which implement IDisposable by default in case of calling Dispose method or not ?

I have read some about GC,Finalizers,Managed & Unmanaged Objects,Disposable pattern @StackOverflow. Currently,I am quite confused about proper usages of GC,Finalizers,Disposable pattern and managed,unmanaged resources terminology. IMHO there are…
erhan355
  • 806
  • 11
  • 23
0
votes
1 answer

Why is finalize method called 2 times in wicket model

In my application I have class which extend wicket model and override finalized method(just delete file which is generated asynchronous). Problem is that finalized method is called immediately after wicket page is loaded for the first time and then…
hudi
  • 15,555
  • 47
  • 142
  • 246
0
votes
1 answer

JRubyClassLoader not getting released

We're running a small JRuby on Rails app under Tomcat 6.0.28 with a Spring-based backend. I've spent some time with the Eclipse Memory Analysis tool and I can definitely tell that instances of the JRubyClassLoader are leaking. I setup our webapp to…
organicveggie
  • 559
  • 5
  • 22
0
votes
1 answer

How to ensure thread is not terminated before finalizer completes

I have an unmanaged class that is running a message loop for a child Win32 window. When the program goes to close, it starts the finalizer for the managed class that holds the unmanaged reference to this class. Because another thread is dependent…
ThisHandleNotInUse
  • 1,135
  • 1
  • 10
  • 23
0
votes
1 answer

How to find the cause of blocking finalizer in .NET?

In Java I need only to press a single key (ctrl-break) to see the stacktrace of a blocking finalizer. Is there a simple solution to see this also in .NET which can understand a Java programmer?
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
0
votes
2 answers

Effective Java - Never depend on a finalizer to update critical persistent state

Why this should not be done? As finalizers will be called when garbage collection is executed, why can't we add persistent related code here?
Rengasami Ramanujam
  • 1,858
  • 4
  • 19
  • 29
0
votes
0 answers

Why doesn't my CriticalFinalizerObject get finalized when a new app domain spins up?

I have an .NET MVC site which spins up child processes for doing background work. I'd like to ensure that those processes are shut down when IIS spins up a new app domain (e. g. on deployment or any change to Web.config). For this purpose, I've…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
0
votes
2 answers

Do Finalizer thread can cause Out of Memory?

Finalizer thread are responsible clearing objects in the finalization queue. Ironically does the same finalizer thread can responsible for OOM?
Mohan Raj
  • 1,104
  • 9
  • 17
0
votes
3 answers

Destructor restrictions - access managed member from destructor

Is it right that in C# Destructor (Finalizer) you can not access managed members of your class? If it is true, why is it? What other C# finalizer restrictions you know? Example: class MyClass { private FileStream _fs; private IntPtr…
AlonP
  • 903
  • 1
  • 9
  • 16
0
votes
1 answer

Should AutoCloseable Iterator to a ResultSet call close from finalizer?

I have an Iterator backed by a ResultSet. I need that for a row-level post-processing. The iterator implements AutoCloseable inteface. The connection remains open up until we iterate through all the rows / iteration interrupted by the user. And…
amdmax
  • 771
  • 3
  • 14
0
votes
1 answer

Why not run the (last) c# finalizers before exiting of the app?

I have a c# Console App (visual studio 2013 express), as follows: class Program { static void Main(string[] args) { var max = 1; for (int i = 0; i < max; i++) { var inherited = new GCInherited(i); …
Gábor Plesz
  • 1,203
  • 1
  • 17
  • 28