finalization

Memory leak in VB

做~自己de王妃 提交于 2019-12-02 09:43:26
We noticed one interesting issue regarding memory management in VB that we do not understand. If anyone could help us with this one, please do. We have a simple class with one single event. We create and destroy 5000 instances of this class and before we run a test we read the process memory usage. At the end we force GC and check the memory again.What we noticed is, that we have a constant memory growing. We did the same sample in C# and we did not run into this issue. Now here is the wired point. If we omit event declaration from class the memory will be cleaned as we expected. Does any one

Does the finalization routine need to be elemental in order to be called on the elements of allocatable array that goes out of scope?

北城以北 提交于 2019-11-29 15:44:44
If I have an allocatable array of a finalizable derived type, will the finalizer be called on every individual element when the array goes out of scope? Here is a small code example that illustrates the question: module LeakyTypeModule implicit none private type, public :: LeakyType real, pointer :: dontLeakMe(:) => null() contains procedure :: New final :: Finalizer end type contains subroutine New(self, n) class(LeakyType), intent(out) :: self integer , intent(in) :: n allocate(self%dontLeakMe(n)) self%dontLeakMe = 42.0 end subroutine subroutine Finalizer(self) type(LeakyType), intent(inout)

Should Java 9 Cleaner be preferred to finalization?

我们两清 提交于 2019-11-28 23:26:11
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 the PhantomReference mechanism instead of GC finalization. At first, I thought it was just a way add finalization to third-party classes. However, the example given in its javadoc shows a use-case that can easily be rewritten with a finalizer. Should I be rewriting all of my finalize methods in terms of Cleaner? (I don't have many, of course. Just

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

最后都变了- 提交于 2019-11-28 20:56:35
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". All other objects are unreachable. The next step is to check every unreachable object and determine whether it can be sweeped right now or it should be finalized at first. The gc thinks the next way if the object's finalize method has a body then this object is finalizable and should be finalized; if the object's finalize method has an empty body

PhantomReference with null queue

为君一笑 提交于 2019-11-28 13:58:45
Java allow to write: new PhantomReference(new Object(), null) At this case new Object() will be collected? As I understand, phantom reference is alternative of finalize() method usage. And after appearing reference in queue, I need to do some additional actions and then run clear() java doc stays: It is possible to create a phantom reference with a null queue, but such a reference is completely useless: Its get method will always return null and, since it does not have a queue, it will never be enqueued What does mean if it will never be enqueued? As I understand it means that after finalize

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

狂风中的少年 提交于 2019-11-28 10:22:22
问题 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 gc to free memory. But why allocation phase can be increased? 回答1: I have searched for the original statement: On my machine, the time to create and destroy a simple object is about 5.6 ns. Adding a finalizer increases the time to 2,400 ns. In other

Does the finalization routine need to be elemental in order to be called on the elements of allocatable array that goes out of scope?

空扰寡人 提交于 2019-11-28 08:52:35
问题 If I have an allocatable array of a finalizable derived type, will the finalizer be called on every individual element when the array goes out of scope? Here is a small code example that illustrates the question: module LeakyTypeModule implicit none private type, public :: LeakyType real, pointer :: dontLeakMe(:) => null() contains procedure :: New final :: Finalizer end type contains subroutine New(self, n) class(LeakyType), intent(out) :: self integer , intent(in) :: n allocate(self

Should Java 9 Cleaner be preferred to finalization?

感情迁移 提交于 2019-11-27 21:42:12
问题 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 the PhantomReference mechanism instead of GC finalization. At first, I thought it was just a way add finalization to third-party classes. However, the example given in its javadoc shows a use-case that can easily be rewritten with a finalizer. Should

What is the purpose of finalization in Java?

谁说胖子不能爱 提交于 2019-11-27 20:48:39
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 for the garbage collector to access the object. Then finalize is invoked to do a final clean up processing after which the garbage collector can be invoked. Is this an accurate description of finalization? Péter Török The garbage collector is working automatically in the background (although it can be explicitly invoked, but the need for this should

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

浪尽此生 提交于 2019-11-27 13:32:42
问题 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". All other objects are unreachable. The next step is to check every unreachable object and determine whether it can be sweeped right now or it should be finalized at first. The gc thinks the next way if the object's finalize method has a body then this