Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Garbage collection....

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends
As we know java has automatic memory management by the process name called garbage collector. the JVM will call this GC for releasing the memory of the objects thats has no more references. as we know objects are eligable for garbage collection by Nulling a Reference,Reassigning a Reference Variable and Isolating a Reference. So in my example

in this code the reference variable myRef is pointing to myclassObject as the main method runs out of its scope does the JVM make myRef eligable for GC.
suppose i mage a change

when could my reference variable myRef is eligable for GC ?
 
Sheriff
Posts: 9690
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Santhosh, let me modify your code a bit



Now when line #10 is executed, then this is the object representation in the heap



So now in this object of myclass, the ref points to itself. So basically myRef in main method and myRef.ref point to the same object. Now when we set myRef to null, it no longer points to this object. And myRef.ref also cannot be accessed as myRef now points to null. So basically you cannot access this object.



Thus this object will be eligible for GC...
 
Marshal
Posts: 22458
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is called an island of isolation.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the object leave in heap even after the code run's by the JVM.
 
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santhosh.R gowda wrote:Does the object leave in heap even after the code run's by the JVM.

Ankit has already given you the details. The correct answer is "don't know" because the garbage collector probably doesn't run during the execution of such a small application.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic