This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Garbage Collection  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What objects would be eligible for garbage collection?
 
Marshal
Posts: 4618
298
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the purposes of copyright and correct attribution, please state where this example has come from.

What do you think the answer is? Are any objects created at all?
 
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please also copy the question exactly. You must say when you are counting objects eligible for GC. Also copy the code exactly; I don't know how many of the compiler errors were in the original and how many are because you introduced copying errors.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garbage collection has more profound impact on the application in contrary to what most engineers think. In order to optimize memory and garbage collection settings and to troubleshoot memory-related problems, one has to analyze Garbage Collection logs.
Enabling GC logs
GC Logging can be enabled by passing below-mentioned system properties during application startup

Until Java 8:

Below is the system property that is supported by all version of Java until JDK 8.


From Java 9:

Below is the system property that is supported by all version of Java starting from JDK 9.

 
Campbell Ritchie
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don';t add points irrelevant to the original question.
 
Anu Gaur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this question in one of internal papers of my organization. I dont know exact reference.

Also, as per my understanding, all objects created ll be valid for garbage collection at the end of program as main reference is made to point null and thus all objects created ll be lying on heap without any external reference.
 
Tim Cooke
Marshal
Posts: 4618
298
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding, that code will not compile.
 
Anu Gaur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile errors removed :
 
Campbell Ritchie
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anu Gaur wrote:. . . internal papers of my organization.

I hope you are allowed to quote it, though I can see no harm in the code you quoted myself.

. . . all objects created ll be valid for garbage collection at the end of program as main reference is made to point null . . .

That is correct, assuming the code will run at all. But for an exam, they will want to know how many objects are eligible for GC.
 
Anu Gaur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two objects should be created one of SmallClass and one of BigClass. Two references a and bigClass should be pointing to BigClass object and one reference smallClass should be pointing to SmallClass object. As soon as a is pointed to null, all other references are pointing to each-other somehow and not touched by external program thus valid for garbage collection.
 
Campbell Ritchie
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is that? At the end of line 17?
 
Anu Gaur
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, at line 17, a is pointed to null.
 
Campbell Ritchie
Marshal
Posts: 64157
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right about two objects being eligible for GC after line 17, but how may objects can you see not eligible for GC?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!