java - What is the relationship between the PhantomReference and ReferenceQueue? -


I'm a little confused about the phantom reference in Java when I saw in online articles that most of them have said That the Phantom Return object will return empty after creation, even though we get the reference () and also mentioned that the objects are accessible on the Fantamali, will be inserted into the context, when the Phantom reference will be removed,

I have tried the following code example, but I have confusion about the result.

  device = tool (new); Reference queue queue = new reference qi (); Phantom Reference PR = New Phantom Reference (tool, queue); Println (pr.get ()); Println (queue.poll ());   

Zero is printed above two statements. If pr.get () returns the tap, then does that mean that the garbage collected by the public is collected? If so, why is the object still not added to the priority queue?

Can someone help me clarify this thing?

Please describe these two words in the same way

Thanks a lot

The reference object referenced Returns because the context of a phantom reference is always unavailable, this method always produces blank.

You can not know whether it was collected or not get () .

If so, why is the object still not added to the priority queue

state

if the garbage collector Determines at a fixed time that in the context of a phantom reference the phantom is accessible, then then at that time or after some time will reference this context.

So either this example was not collected by the poll () (non-blocking) garbage or example garbage was collected, but FONTAM REFERENCE was not added to contextQuality to set the strong context of related null and request for GC.

, but also blocks delete at context from the queue.

  device = null; Println (pr.get ()); System.gc (); Println (queue.remove ()); // Block and wait for it to be added    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -