Questions tagged [finalize]

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

A finalize(), or 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 finalize() 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.

Starting Java9. finalize() method has been officially deprecated. javadoc for Java9's java.lang.Object finalize()

228 questions
0
votes
0 answers

Garbage Collection and Finalize()

I am trying to write a program that moves an elevator randomly through the floors of different buildings with different stories. I need to use the finalize() method to clean up after every building. And I have different floors choosing to activate…
0
votes
0 answers

Java reference-aware cache

I have memory-expensive objects, that sometimes come with identical content. I would like to cache them as long as they're referenced at least once, and evict from the cache if all referenced are destroyed. Is there a standard solution for that in…
Zyx
  • 336
  • 4
  • 18
0
votes
2 answers

RxJS finalize operator vs tap({ finalize: () => {} })

Is there any difference between A and B? Are there any cases where one would behave differently than the other? A) observableHere .pipe( finalize(() => { // Do stuff here }) ) B) observableHere .pipe( …
JWess
  • 602
  • 7
  • 17
0
votes
1 answer

java System.gc() only works if I set obj=null implicitly?

I'm using Java 8 on windows 10 and I have this code snippet to test how System.gc() works: public class testGc{ static class MyObject{ @Override protected void finalize() throws Throwable{ // not called when System.gc() …
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
0
votes
0 answers

Many objects with finalize() in heap, i.e. PgConnection

When analyzing a heap dump of my application I noticed 1478 instances of java.lang.red.Finalizer class. 501 of them was referencing org.postgresql.jdbc.PgConnection class and another 501 sun.security.ssl.SSLSocketImpl. The length of the queue in…
piotom
  • 81
  • 1
  • 10
0
votes
0 answers

Problem with MPI_Finalize at the end of a code

I have a Fortran 90 code which uses the MPI library. At the end of the code, I have the following statements to finish the program: call MPI_Finalize(ierr) write(6,*) ierr stop The code to MPI_Finalize seems to result in an endless loop and the…
Siegfried
  • 49
  • 3
0
votes
0 answers

AlreadyFinalized("Context was already finalized.")

from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import padding import os class EncryptionManager: def __init__(self): …
0
votes
2 answers

when is finalize called when deployed on tomcat

I have created a simple Java class as follows: I pass content as a byte-array and a Filename and the class creates a TempFile somewhere. import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; public class TempFile…
sennzz
  • 25
  • 3
0
votes
2 answers

calling finalize() of super class in Kotlin

I have the following Java code I wanted to convert into Kotlin: @Override protected void finalize() throws Throwable { try { release(); } finally { super.finalize(); } } In the official documentation I have found…
abdullah celik
  • 511
  • 1
  • 6
  • 17
0
votes
0 answers

Unload a dll loaded by a classloader in Java11

I had a scenario where I need to perform database connectivity using Java11 twice using Windows Authentication on SQL server. Initially, the sqljdbc_auth.dll is loaded for the first call and the connection was successful. But, in order to make the…
0
votes
1 answer

Trying to decrement my static count variable in java jdk 1.8.0

Using finalize function, when I point an object to null it’s not decrementing although it is incrementing properly. I also mentioned garbage collector which will listen to its own self, I know but why it’s not working. I am using java jdk…
A.F.R.N
  • 11
  • 1
  • 6
0
votes
1 answer

How do i override the finalize() method of the class object itself?

My problem is straightforward. I have a class that has a static ThreadPoolExecutor object. This threadpoolexecutor object is thus shared by all the instances of the class. If i were to shut the entire application down the shared class object would…
Maurice
  • 6,698
  • 9
  • 47
  • 104
0
votes
0 answers

Java testing: How to run custom code when instances become eligible for GC?

I want to know if there is a way to detect when a CompletableFuture instance becomes eligible for garbage collection before anyone ever called .get() on it. I want to do this detection during Java testing, where I can use any tools from…
user102008
  • 30,736
  • 10
  • 83
  • 104
0
votes
0 answers

How to write code coverage for subscribe method with finalize keyword in Angular Jamsine?

Angular version: "@angular/core": "6.1.7" Jamsine version: "jasmine-core": "~2.8.0" File name: app.component.ts (Method inside the component file) testFunction() { this.testClassService.testServiceFunction(data).pipe(takeWhile(() =>…
ArunValaven
  • 1,753
  • 2
  • 25
  • 44
0
votes
0 answers

Why can't javac compile class with finalize

I have read similar questions on the stackoverflow,but they answer what to do about it (compile it with -Xlint:deprecation) and not why the error occurs in the first place.I want to know why the error popped in the first place. The Box Class public…
Mrak Vladar
  • 598
  • 4
  • 18