Home > Back-end >  The GC to reclaim really tagged objects at least twice
The GC to reclaim really tagged objects at least twice

Time:09-22

"to announce a tag object death will experience at least two processes: if by accessibility analysis without reference chain connected to GC Roots, is the first time tag and a filter, filter condition is whether the object has to perform the finalize () method, when the object does not cover the finalize () method, or finalize () method has been called virtual machine, virtual machine will both as" there is no need to perform, "
If an object is necessary to perform the finalize () method, which will be placed in the F - Queue Queue, and later set up a virtual machine, the lower priority thread finalizers to execute it, virtual chance to trigger this approach, but don't wait for it to perform, or if an object in the finalize () method is performed in a slow, memory recovery system would collapse, finalize () method is an object finally a chance to escape death, GC will later F - the object in the Queue for the second small tag, if the object before the second marker could not save themselves will be recycled, saving way is as long as the associated with any object reference chain, "

The above content from the books, if according to the above, then when the object's finalize () method is not necessary to perform, it is not only marked a can?

CodePudding user response:

Twice in the second is to do some confirmation, to prevent the recycling, and cited the etc

CodePudding user response:

To handsome but not to say that the second choice is the small sign? And is in users do not have to rewrite the finalize () method or didn't call the finalize () method of the object will do the second tag,,,,,,, still a little don't understand

CodePudding user response:

The original poster to read, is a finalize () object and not perform finalize () method will be in the F - and the second tag in the Queue, for which no finalize () method or has been performed this method still need to be recycled mark only one can be recycled,

CodePudding user response:

I read about, is to feel the contradiction of the book, he said the first sentence: GC objects at least twice before, and I'm from it in the words of the following, feel is a well, and it is as same as what you said, but the notes on the net also said at least twice, contradiction

CodePudding user response:

The the words together in front of the landlord to see admire, " even in accessibility analysis algorithm, unreachable object, also is not "the death", at that time they temporarily in the stage of "probation" , to truly an object declared dead ", people is the precondition of the suspended object to undergo two tag,

CodePudding user response:

In Java, every object has a unique "count", is used to mark the referenced number: if the add a variable reference, or minus one. If 0 indicates that the variables to be GC recycling

CodePudding user response:

refer to 6th floor abc_12366 response:
in Java, every object has a unique "count", is used to mark the referenced number: if the add a variable reference, or minus one. If 0 indicates that the variables to be recycle GC


Nonsense,,,,

CodePudding user response:

refer to 7th floor bihanren32 response:
Quote: refer to the sixth floor abc_12366 response:

In Java, every object has a unique "count", is used to mark the referenced number: if the add a variable reference, or minus one. If 0 indicates that the variables to be recycle GC


Nonsense,,,,

No trouble shoot the breeze with you, you said someone must have basis!

CodePudding user response:

I also feel very contradictory, if suspended object does not cover the finalize () method, it does mark a recycled, the building Lord have clear? Ask ~ ~

CodePudding user response:

refer to the eighth floor abc_12366 response:
Quote: refer to 7th floor bihanren32 response:

Quote: refer to the sixth floor abc_12366 response:

In Java, every object has a unique "count", is used to mark the referenced number: if the add a variable reference, or minus one. If 0 indicates that the variables to be recycle GC


Nonsense,,,,

No trouble shoot the breeze with you, you said someone must have basis!
also reference counting I ask you
Class A {
Public Object o;
}

A a1=new A ();
A a2=new A ();
A1. O=a2;
A2. O=a1;
Reference counting how recycling for me

CodePudding user response:

First you need to have a clear, there are many kinds of the GC, including (reference count) is an ancient JavaGC mechanism, but as you say, in dealing with the problem (circular reference), so now basically adopts the mechanism of accessibility of (GC), are all right, just their respective applied to different problems,

CodePudding user response:

If the object is not necessary to perform the finalize () method, marking a recovery

CodePudding user response:

I have a contradiction, also feel here,

CodePudding user response:

Personal understanding of the process at least two tags:
1) the first big sign: if there is no cover finalize () method, the tag, wait a second great tags, if covered, entered into F - Queue and small tag
2) the second great sign: F - Queue, after the completion of small-scale tag on all meet the conditions (including does not cover the finalize () method and carried out the finalize ()) of the object in a collection of "the recovery", and mark the second small object to remove "the recycling" the operation of the collection of
- as for the second small "tag" is the first time in large and second big marking, the second is the relative to the first big sign, not is the second sign, is also the author of semantic expression!
- why does not cover the finalize () method of the object is no longer the first big tag immediately after release, 1/F, is said, to confirm again, by the way, could you wait F - Queue small tag will clean up later

CodePudding user response:

I also just saw here, little doubt the Internet in this post,
The building Lord, I said I understand, you are on the right analysis, if a class does not rewrite the finalize method, seems like it is ok that just need to mark time; If you rewrite the finalize method so it could "save yourself" within the finalize method, however, if the "save itself" classes contain other without rewriting the finalize method of application of time? So mark only one clear idea or some problems,
Such as the following:
 
Public class FinalizeEscapeGC {
Class A, {}.
Private static FinalizeEscapeGC SAVE_HOOK=null;
Private A A=new A ();
Public void isAlive () {
System. Out.println (" yes! I am still alive. ");
}

@ Override
Protected void finalize () throws Throwable {
super.finalize();
System. Out.println (" the finalize method executed!" );
FinalizeEscapeGC. SAVE_HOOK=this;
}

Public static void main (String [] args) throws Throwable {
SAVE_HOOK=new FinalizeEscapeGC ();

SAVE_HOOK=null;
System. The gc ();
Thread.sleep(500);
If (SAVE_HOOK!=null) {
SAVE_HOOK. IsAlive ();
} else {
System. Out.println (" no, I 'm dead!" );
}
}
}

Class FinalizeEscapeGC rewrite the finalize method, class A not rewrite the finalize method, when performing SAVE_HOOK=null, after the two objects are inaccessible, if to the object of the class A tag only once is clear, then the class FinalizeEscapeGC properties after the finalize method to "save" A it was cleared, not as the original that FinalizeEscapeGC,

CodePudding user response:

There is a problem: and F - Queue Queue object inside keep connection is palpable or reach? If it was palpable, the analysis of the above is not right, can hit will not be cleared, property a,, (not to baidu, for this problem may be a little silly force, just began to learn the JVM)
  • Related