SlideShare a Scribd company logo
Java Reference Objects
Basic Understanding
GC’s job
● Identity objects that are no longer in use
● Reclaim the memory
What is “use”
● An object can be reached by a program in its current state
Main Thread
forked Threads
RunnClass#
runningMethod..
Root set of reference
static reference
JNI API registered
references
Reachable
Garbage Collection
● All other than reachable objects are unreachable
● Unreachable objects are eligible for garbage collection
Red box are
unreachable objects
Reference object
● Reference objects will be treated differently by GC
● Concept: Refernece and Referent
SoftReference Image
Reference Referent
Object Reachability
● Reference Objects API gives us strengths of object reachability
○ Strongly Referent
○ Softly Reference
○ Weakly Reference
○ Phantomly Reference
● By this API we can get a limited amount of interaction with GC
according to the strength of the object’s reachability
Strongly reachable
● An object is reachable from the root set of references
Weak Reachable
● The only way to reach an object involve at least one weak reference object
● Weak referenced objects are eligible for collection
● Weak reference object allow us to refer to and object without keeping it from
being collected
● When a referenced object is
collected, the value of
WeakReference will be set
to null
● Weak reference life time
won’t be extended
Softly Reachable
● Not a strongly reachable
● No weak reference
● No Phantom reference
● One or more soft reference
● GC must clear all soft reference before throwing OutOfMemoryError
● GC will clear it when memory is not enough
● GC may not clear it when it’s used recently, life time may be extended
● Often used to implement a cache
Phantomly Reachable
● When an object has no weak reference and soft reference, or become
unreachable by itself. The object will be phantomly referenced
● PhantomReference has a constructor: ReferenceQueue. It can be used to
monitor finialization status controlled by GC.
ReferenceQueue
● A data structure for you to find out when an object becomes softly, weakly, or
phantomly reachable.
Reference
http://pawlan.com/monica/articles/refobjs/

More Related Content

PDF
Kotlin & Arrow the functional way
PDF
Kotlin & arrow: the functional way
PDF
Promoter – A Python Project for Replicating a JSS via the API
PPTX
J90 X
PPTX
Java GC
PDF
Garbage collection 介紹
PDF
Java gc
PDF
Java Garbage Collection
Kotlin & Arrow the functional way
Kotlin & arrow: the functional way
Promoter – A Python Project for Replicating a JSS via the API
J90 X
Java GC
Garbage collection 介紹
Java gc
Java Garbage Collection

Similar to Java reference objects basic (17)

PDF
Memory Management in RubyMotion
PDF
WeakReferences (java.lang.ref and more)
PDF
Advance Features of Hibernate
PDF
Design Patterns in Object Oriented Design
PPT
Adapter Poxy Pattern
PPSX
Core Java for Selenium
PDF
Better Page Object Handling with Loadable Component Pattern
PPTX
React more than just components
PPTX
React learning in the hard way
PPTX
Design Pattern lecture 4
ODP
Hibernate complete Training
PPTX
Presentation-Session3
PPTX
Better Page Object Handling with Loadable Component Pattern
PPT
2010 05-21, object-relational mapping using hibernate v2
PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
PDF
Resource management in java bof6823 - java one 2012
PDF
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Memory Management in RubyMotion
WeakReferences (java.lang.ref and more)
Advance Features of Hibernate
Design Patterns in Object Oriented Design
Adapter Poxy Pattern
Core Java for Selenium
Better Page Object Handling with Loadable Component Pattern
React more than just components
React learning in the hard way
Design Pattern lecture 4
Hibernate complete Training
Presentation-Session3
Better Page Object Handling with Loadable Component Pattern
2010 05-21, object-relational mapping using hibernate v2
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Resource management in java bof6823 - java one 2012
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Ad

More from Isaac Liao (9)

PDF
Design of everyday things fundamental principles of interaction - V2
PDF
Design of everyday things fundamental principles of interaction
PDF
Effective java item 80 and 81
PDF
Effective java item 80 prefer executors, tasks, and streams to threads
PDF
Coding practice
PDF
Concurrent package classes
PDF
Count downlatch & implementation
PDF
Study effective java item 78 synchronize access to mutable data
PDF
Concurrency
Design of everyday things fundamental principles of interaction - V2
Design of everyday things fundamental principles of interaction
Effective java item 80 and 81
Effective java item 80 prefer executors, tasks, and streams to threads
Coding practice
Concurrent package classes
Count downlatch & implementation
Study effective java item 78 synchronize access to mutable data
Concurrency
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Digital Systems & Binary Numbers (comprehensive )
PPT
Introduction Database Management System for Course Database
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Transform Your Business with a Software ERP System
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ai tools demonstartion for schools and inter college
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Digital Systems & Binary Numbers (comprehensive )
Introduction Database Management System for Course Database
Odoo Companies in India – Driving Business Transformation.pdf
Softaken Excel to vCard Converter Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Transform Your Business with a Software ERP System
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Design an Analysis of Algorithms II-SECS-1021-03
ai tools demonstartion for schools and inter college
Reimagine Home Health with the Power of Agentic AI​
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Upgrade and Innovation Strategies for SAP ERP Customers
top salesforce developer skills in 2025.pdf

Java reference objects basic

  • 2. GC’s job ● Identity objects that are no longer in use ● Reclaim the memory
  • 3. What is “use” ● An object can be reached by a program in its current state Main Thread forked Threads RunnClass# runningMethod.. Root set of reference static reference JNI API registered references Reachable
  • 4. Garbage Collection ● All other than reachable objects are unreachable ● Unreachable objects are eligible for garbage collection Red box are unreachable objects
  • 5. Reference object ● Reference objects will be treated differently by GC ● Concept: Refernece and Referent SoftReference Image Reference Referent
  • 6. Object Reachability ● Reference Objects API gives us strengths of object reachability ○ Strongly Referent ○ Softly Reference ○ Weakly Reference ○ Phantomly Reference ● By this API we can get a limited amount of interaction with GC according to the strength of the object’s reachability
  • 7. Strongly reachable ● An object is reachable from the root set of references
  • 8. Weak Reachable ● The only way to reach an object involve at least one weak reference object ● Weak referenced objects are eligible for collection ● Weak reference object allow us to refer to and object without keeping it from being collected ● When a referenced object is collected, the value of WeakReference will be set to null ● Weak reference life time won’t be extended
  • 9. Softly Reachable ● Not a strongly reachable ● No weak reference ● No Phantom reference ● One or more soft reference ● GC must clear all soft reference before throwing OutOfMemoryError ● GC will clear it when memory is not enough ● GC may not clear it when it’s used recently, life time may be extended ● Often used to implement a cache
  • 10. Phantomly Reachable ● When an object has no weak reference and soft reference, or become unreachable by itself. The object will be phantomly referenced ● PhantomReference has a constructor: ReferenceQueue. It can be used to monitor finialization status controlled by GC.
  • 11. ReferenceQueue ● A data structure for you to find out when an object becomes softly, weakly, or phantomly reachable.