• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Cannot understand the following GC example from Khalid Mughal

Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following exampleis used to demonstratde the garbage collection mechanism. I am not able to understand the example very clearly:
The code is as follows:
class SuperBlob {
static int idCounter;
static int population;
protected int blobId;
public SuperBlob(){
System.out.println("Super blob is getting called");
protected void finalize() throws Throwable {
class Blob extends SuperBlob {
int[] fat;
public Blob(int bloatedness){
fat=new int[bloatedness];
protected void finalize() throws Throwable{
public class Finalizers {
public static void main(String[] args){
int blobsRequired, blobSize;
try {
blobSize =Integer.parseInt(args[1]);
catch(IndexOutOfBoundsException e){
System.out.println("Usage:Finalizers <number of blobs> <blob size>");
for(int i=0;i<blobsRequired;++i){
new Blob(blobSize);
System.out.println(SuperBlob.population+"blobs alive");
a. What is being garbage collected in the above example? Is it int array fat? or is it Object Blob?
b. Will this have different results on different jvm's?
c. Why is super(finalize) being called in class
SuperBlob? What is the use of that? What will that call?
Could someone please explain the above.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic