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

Do callback on Java object just BEFORE it's garbage collected

Backstory: So I had this great idea, right? Sometimes you're collecting a massive amount of data, and you don't need to access all of it all the time, but you also may not need it after the program has finished, and you don't really want to muck…
Erhannis
  • 4,256
  • 4
  • 34
  • 48
0
votes
1 answer

Meaning of "The finalize method is never invoked more than once by a JVM for any given object." in case of Object Resurrection?

As per Java Doc: The finalize method is never invoked more than once by a Java virtual machine for any given object. Can the above policy help to make an object immortal? If I resurrect an object one time from finalize() method then will that…
hsingh
  • 661
  • 5
  • 26
0
votes
1 answer

Finalizer Blocked Issue

hi I have searched through the various posts and answers regarding a perpetually blocked finalizer thread. Several seem useful, but I am needing additional clarity. In my application API calls are coming from a Web Service to an NT Service. I…
SteveSims
  • 535
  • 6
  • 19
0
votes
2 answers

How to call a finalizer, upon closing a windows form?

I am working on a dll in vb.net. I would like to call a function from within the dll but when the form that uses the dll is closed. i.e abc dll being used in xyz form. xyz form is closed, a function func needs to be called. func has to be defined in…
0
votes
2 answers

C# Destructor vs IDisposable

Just trying to understand why destructor is called outside of the scope of USING after instance is dispose. I know there is no need for destructor when IDisposable is implemented. Here is my example: using System; namespace Destructor { class…
cembo
  • 1,039
  • 2
  • 9
  • 18
0
votes
2 answers

Why isn't the __del__ method called?

In python3's multiprocess, can't call the __del__ method. I've read other issues about circular references,but I can't find the situation in multiprocess. There is a circular reference in foo, __del__ will be called when foo is called…
0
votes
1 answer

Troubleshooting memory leak possibly due to Finalizer thread malfunction

We have a WinForms application installed in hundreds of clients. In some of them, memory usage starts going up over time with apparent no reason, until an OutOfMemoryException is eventually thrown. We used DebugDiag Collection and Analysis to try…
armarru
  • 33
  • 4
0
votes
1 answer

Memory leak on Wildfly 10.1.0.FINAL (java.lang.ref.Finalizer / ActiveMQConnection)

We have a java web application that sends (JobsController.java) and receives messages (JMSMessageListener.java) via JMS. After running the application under constant load for 24 hours and taking heap dumps, I observe a constant increase in memory…
Choesang
  • 1,225
  • 1
  • 14
  • 23
0
votes
1 answer

A Case For a C# Finalizer

This question has to do with this post and some of the answers, especially the answer from @EricLippert . I want to encapsulate reading and writing an Informix SE database inside of a C# class. I want the OdbcConnection, OdbcCommand, and…
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
0
votes
1 answer

Why creators of Java specifications did not mandated finalizer chaining just like constructors?

We have Constructors in Java which are analogous to Constructors in C++ which would create the object by automatically chaining(Consirering default non parameterized constructors) its constructors from base class to object being constructed. Now we…
Xinus
  • 29,617
  • 32
  • 119
  • 165
0
votes
0 answers

Finalizer object in jmap histogram

What can be the reason I am seeing 2k objects of java.lang.ref.Finalizer in my jmap histogram 154: 2224 88960 java.lang.ref.Finalizer For Object.finalize() , Finalizer thread creates a new object everytime ?
samsudh
  • 73
  • 1
  • 8
0
votes
1 answer

How do I finalize the main thread?

Is there a way to execute a function when the main thread of a python process is shut down (normally or with an uncaught exception)? I was hoping atexit.register would provide that functionality, but apparently it does not get invoked when the main…
max
  • 49,282
  • 56
  • 208
  • 355
0
votes
1 answer

How to ensure closing of a connection at the end of the program

I connect to a DB using a CloseableHttpClient. I use this connection to query the DB and at the end of the program I want to ensure that I log out and close the connection. Where in the code should I logout and close the CloseableHttpClient? If I…
Roland
  • 7,525
  • 13
  • 61
  • 124
0
votes
1 answer

Finalizer bloqued hanging the application

Today we received a CrashDump of an application that was hung. Running it thru DebugDiag we got the following information: Analysis Summary Error Description Recommendation The finalizer thread 5 in this WordHangs.dmp is blocked Review…
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
0
votes
2 answers

C#: How to make sure the class finished the work, without relying on dependents?

I have a class that collects a string. There is a method Commit, that writes the string to a target file. If a string is collected, but the commit is never invoked, I want to report an error into a log file. IDisposable will not solve the problem,…
polina-c
  • 6,245
  • 5
  • 25
  • 36