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
16
votes
1 answer

Why does SHA1.ComputeHash fail under high load with many threads?

I'm seeing an issue with some code I maintain. The code below has a private static SHA1 member (which is an IDisposable but since it's static, it should never get finalized). However, under stress this code throws an exception that suggests it has…
MvdD
  • 22,082
  • 8
  • 65
  • 93
16
votes
4 answers

Can we switch off finalizers?

As there is little guarantee about when and even if finalizers run and finalizers are almost considered a smell nowadays - is there any way to persuade the JVM to completely skip all finalization processes? I ask because we have a mammoth…
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
16
votes
3 answers

what will the Finalizer thread do if there is a infinite loop or deadlock in the Java finalize method

what will the Finalizer thread do if there is a infinite loop or deadlock in the Java finalize method.
andy
  • 3,951
  • 9
  • 29
  • 40
16
votes
2 answers

Execute code when VisualStudio debugger is exiting

I had assumed that when terminating debugging (such as by hitting the Stop button, or hitting Shift+F5), that any class implementing a finalizer or IDisposable would be, well, disposed. I have some classes that implement IDisposable. There are a…
CoolUserName
  • 3,715
  • 6
  • 26
  • 30
15
votes
7 answers

What's the use of the __del__() method in Python?

From Python documentation: It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits. As far as I understand, there is also no way to guarantee an object stops existing before the interpreter…
PieterNuyts
  • 496
  • 5
  • 20
14
votes
5 answers

Should GC.SuppressFinalize be called on objects that do not have a finalizer?

For some reason FXCop seems to think I should be calling GC.SuppressFinalize in Dispose, regardless of whether I have a finalizer or not. Am I missing something? Is there a reason to call GC.SuppressFinalize on objects that have no finalizer…
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
14
votes
1 answer

Does Perl 6 automatically call any special methods when it cleans up an object?

I thought that Rakudo got finalizer support several years ago but I couldn't find the documentation for it (maybe it goes in Classes and Objects). Listing all the methods in a class didn't seem like the thing I was looking for. class Butterfly { …
brian d foy
  • 129,424
  • 31
  • 207
  • 592
14
votes
1 answer

Will SqlConnection get disposed by GC?

Disclaimer: I know IDisposable should be implemented when dealing with unmanaged resources. The rest of the code should be deterministic and do using (...) { } (equivalent of try {} finally { Dispose(); }) to guarantee a cleanup as soon as…
Nelson Rothermel
  • 9,436
  • 8
  • 62
  • 81
14
votes
1 answer

What is the scope of finalizer thread - per application domain or per process?

Based on all my reading there should be one GC thread to invoke all finalizers. Now, the question is what is the scope of this "one" thread - per process or per application domain, as the whole intention of domains is to separate and make…
Sunny Milenov
  • 21,990
  • 6
  • 80
  • 106
14
votes
2 answers

Finalizers for JavaScript objects

Suppose I have some asm.js code, probably created by emscripten. Suppose it has some kind of rather large heap allocated structure, which gets returned by a asm.js function as a pointer that is picked up by some JavaScript library to be wrapped in a…
MvG
  • 57,380
  • 22
  • 148
  • 276
13
votes
2 answers

remove kubernetes service-catalog finalizer with cli

I'm trying to provision/deprovision service instance/binding from my cloud provider (IBM cloud private), Currently, there is a bug that if the service is not deprovisioned in ICP, that leaves me the orphan service instance on my ICP environment…
XYZ_Allen
  • 253
  • 2
  • 3
  • 15
13
votes
2 answers

shutdown hook vs finalizer method

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…
S Kr
  • 1,831
  • 2
  • 25
  • 50
13
votes
2 answers

Advanced debugging advice in WPF GarbageCollection

Situation We are running a large WPF application which does not release memory for quite some time. It is not a real memory leak, as the memory will be released eventually. I know that normally, this would not be considered to be a problem.…
12
votes
2 answers

reg.finalizer() in an R package does not execute at the end of an R session

From the documentation ?reg.finalizer in R: Inter alia, it provides a way to program code to be run at the end of an R session without manipulating .Last. For use in a package, it is often a good idea to set a finalizer on an object in the…
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
12
votes
6 answers

Very strange OutOfMemoryError

As always, a lengthy problem description. We are currently stress testing our product - and we now we face a strange problem. After one to two hours, heap space begins to grow, the application dies sometime later. Profiling the application shows a…
mtraut
  • 4,720
  • 3
  • 24
  • 33
1 2
3
29 30