Questions tagged [finalization]

Finalization is intended for questions regarding programmatically releasing memory in conjuction with garbage collection, external resources and weak references.

References

57 questions
2
votes
1 answer

How to force the definition of a destructor

I would like to force inheriting classes to define a destructor in Fortran >= 2008. So far I have tried several variations of: type, abstract :: parent_class_t contains final, deferred, pass :: cleanup end type which don't even compile. How do…
mcocdawc
  • 1,748
  • 1
  • 12
  • 21
2
votes
0 answers

JNI non-Java class members

I want to create a Java wrapper against some third-party library with C interface. The library operates on a complex Context entity which is essentially a C++ object (C++ is used internally in that library, but API is in pure C). It would be natural…
Basilevs
  • 22,440
  • 15
  • 57
  • 102
2
votes
1 answer

why allocation phase can be increased if we override finalize method?

I have heard that in Joshua Bloch book written that allocation and memory collection might be increased to 430 times if we override finalize method. It is clear for me that memory collection can work slower because additional iteration requred for…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
2
votes
3 answers

Is it ok not to free objects before unit unloads from memory (finalization section)?

Since the process will be killed by OS and all memory allocated will be recycled anyway, is it OK not to free objects/resources in the unit finalization section? For example, unit Threading; interface implementation var threadpool:…
justyy
  • 5,831
  • 4
  • 40
  • 73
1
vote
1 answer

What happens to FReachable Objects if they are found to be reachable?

If suppose an object implements the Finalize method but inside it refers an alive static object of the application (bad design! but very possible). Now when GC kicks in and finalises the object by putting it in Finalization queue and then move it to…
WPF-it
  • 19,625
  • 8
  • 55
  • 71
1
vote
1 answer

Prevent object garbage collection before other objects

I have a weakly-referenced array of weak references to further objects like so: public class Foo{ WeakReference[]> cache; } public class Bar{ private final WeakReference[] ownerCache; } The array itself is weakly…
Gergely
  • 159
  • 2
  • 14
1
vote
1 answer

Why does GC not run when finalization queue is using a lot of memory?

I'm starting to learn about GC and finalization, and I've come across quite a simple example where the behaviour of the application is quite unexpected to me. (Note: I'm aware that finalizers should be used only be used with unmanaged resources and…
Aleph
  • 199
  • 2
  • 13
1
vote
1 answer

Creation of controlled type will call finalize on return

I want to create a function for creating and initializing a controlled type (a bit like a factory) in the following manner: function Create return Controlled_Type is Foo : Controlled_Type; begin Put_Line ("Check 1") return Foo; end…
Erik Stens
  • 1,779
  • 6
  • 25
  • 40
1
vote
0 answers

Fortran finalization subroutine does not work when type is an array

Recently I found a serious problem that is in some cases finalization function does not work. Description: I defined a type, say TYPE(testtype):: T, in which many pointers and allocatable arrays being used. And there is a finalization subroutine,…
hengyue li
  • 448
  • 3
  • 17
1
vote
0 answers

What is the purpose of Freachable queue

I am going through .net basics, and i am not able to understand why does .net need freachable queue why can't the finalization stuff happen in the finalization queue. Any help to help me understand this would be deeply appreciated. Thanks!
1
vote
0 answers

PyQt5 and initializing/finalizing the python interpreter

I have an application that can be extended using Python macros. As python is not often used, for every macro, I initialize the python interpreter, run the macro, and then finalize the interpreter. Everything works just fine, with the exception of…
PierreBdR
  • 42,120
  • 10
  • 46
  • 62
1
vote
1 answer

Is manually calling SetLength(array, 0); having a drawback?

I always pair my initialization of a dynamic array with a finalizer in the form of finally SetLength(Array, 0); end; It feels more natural to know exactly when the array gets "destroyed" and allows me smoother transition from arrays to TList…
Gad D Lord
  • 6,620
  • 12
  • 60
  • 106
1
vote
2 answers

Finalization of a log unit called too early

I am running a ISAPI service which runs with IdHTTPWebBrokerBridge (for debugging as standalone EXE) as well as in Apache with mod_isapi (in productive enviroment). While logging some stuff at the destruction of the web module, I found following…
Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67
1
vote
1 answer

In C#, how can a class do its own application-end finalization in a way that works under both ASP.Net and non-web applications?

I have a library class used in ASP.Net and non-web applications that needs end-of-application finalization. Within my project's library, I want the class to do its own end-of-application finalization without requiring a developer to add a call to…
BrianCooksey
  • 1,543
  • 1
  • 12
  • 19
1
vote
1 answer

How do I make sure a certain "finalization" section is the last one executed?

I have many units with "finalization" sections in my Delphi 7 projects. How do I make sure to execute some code last? I tried to write a "finalization" section in the .dpr file but it does not compile.
user382591
  • 1,320
  • 5
  • 19
  • 39