Questions tagged [finalization]

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

References

54 questions
67
votes
15 answers

Should "Dispose" only be used for types containing unmanaged resources?

I was having a discussion with a colleague recently about the value of Dispose and types that implement IDisposable. I think there is value in implementing IDisposable for types that should clean up as soon as possible, even if there are no…
Steve Dunn
  • 18,426
  • 11
  • 59
  • 85
18
votes
1 answer

Do C# try-finally CERs break in iterators?

Apparently, Constrained Execution Region guarantees do not apply to iterators (probably because of how they are implemented and all), but is this a bug or by design? [See the example below.] i.e. What are the rules on CERs being used with…
user541686
  • 189,354
  • 112
  • 476
  • 821
18
votes
4 answers

Should Java 9 Cleaner be preferred to finalization?

In Java, overriding the finalize method gets a bad rap, although I don't understand why. Classes like FileInputStream use it to ensure close gets called, in both Java 8 and Java 10. Nevertheless, Java 9 introduced java.lang.ref.Cleaner which uses…
Aleksandr Dubinsky
  • 19,357
  • 14
  • 64
  • 88
17
votes
3 answers

Do I need to finalize array of records in Delphi?

In my application I have the following record: TTransaction = record Alias: string Description: string Creation: TDateTime Count: Integer end; and I'm using this record in this array: Transactions = array of TTransaction; I'm keeping the…
EProgrammerNotFound
  • 2,333
  • 4
  • 21
  • 54
13
votes
1 answer

C# - What does "destructors are not inherited" actually mean?

Section 10.13, Destructors, of the C# Language Specification 3.0 states the following: Destructors are not inherited. Thus, a class has no destructors other than the one which may be declared in that class. The Destructors section of the C#…
Secret Squirrel
  • 251
  • 3
  • 10
12
votes
5 answers

What is the purpose of finalization in Java?

My understanding of finalization is this: To clean up or reclaim the memory that an object occupies, the Garbage collector comes into action. (automatically is invoked?) The garbage collector then dereferences the object. Sometimes, there is no way…
user244333
9
votes
2 answers

Finalizer statistics

Is there a way to obtain the total number of finalizers registered using runtime.SetFinalizer and which have not yet run? We are considering adding a struct with a registered finalizer to some of our products to release memory allocated using…
Florian Weimer
  • 27,114
  • 3
  • 27
  • 69
9
votes
1 answer

What is the up-front cost of an object being finalizable?

Discussions of finalizable objects in Java typically discuss the common indirect costs that happen when finalizable objects (and their associated resources) cannot be quickly garbage collected. I'm more interested, at the moment, in what the actual…
Theodore Murdock
  • 1,440
  • 1
  • 13
  • 25
8
votes
1 answer

What is the correct way to free an interface behind an OleVariant?

I am trying to find a safe/deterministic way to release an interface which is encapsulated in an OleVariant. AFAICS Delphi releases interface references at the end of a procedure, but in my case I have to do it earlier, because I have to shut down…
Jens Mühlenhoff
  • 13,744
  • 6
  • 47
  • 101
7
votes
1 answer

Does calling `gc()` manually, result in all `finalizers` being executed immediately?

I have some code that I suspect is leaking memory. As the code uses ccall and maintains significant information held inside pointers, which are supposed to be free'd by code that is ccalled during finalizers. In my debugging I am calling gc(). And I…
Lyndon White
  • 24,284
  • 15
  • 77
  • 126
6
votes
1 answer

finalization handle remains in the memory. how to remove this reference?

I need to optimize my application in memory usage. so I used .net performance profiler... but some references in my application are still alive and are never collected by GC even if I force it to collect. The reference that is alive is a…
6
votes
4 answers

Unit finalization order for application, compiled with run-time packages?

I need to execute my code after finalization of SysUtils unit. I've placed my code in separate unit and included it first in uses clause of dpr-file, like this: project Project1; uses MyUnit, // <- my separate unit SysUtils, Classes, …
Alex
  • 5,245
  • 2
  • 33
  • 52
6
votes
3 answers

How is an object marked as finalized in Java (so that the finalize method wouldn't be called the second time)?

The main question is in the topic but let me show my vision of finalization proccess in Java so that I can ask you a little more. Well the gc starts garbage collection by marking all live objects. When all reachable objects are marked as "live".…
Anton Kasianchuk
  • 1,069
  • 4
  • 13
  • 27
5
votes
2 answers

Why code in any unit finalization section of a package is not executed at shut down?

I have an application that uses statically-linked runtime packages as well as designtime packages that use them. For some reason the code in any unit finalization section is not being run at runtime (I can't tell when this started…
avenmore
  • 2,499
  • 2
  • 30
  • 33
5
votes
1 answer

Finalizer Thread Id

We are seeing a memory leak with one of our WCF applications and I was wondering if someone could clarify something for me. Using windbg I ran !finalizequeue and it shows thousands of objects in each Heap set as "Ready for finalization". Heap…
Dan H
  • 1,750
  • 2
  • 21
  • 35
1
2 3 4