Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Doubt in GC

Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of DANS question

class I {
private String name;
public void finalize() {System.out.print(name);}
public I(String s) {name = s;}
class J {
private static void m1(I[] a1) {
a1[0] = a1[1] = a1[2] = null;
public static void main (String[] args) {
I[] a1 = new I[3]; // 1
a1[0] = new I("A"); // 2
a1[1] = new I("B"); // 3
a1[2] = new I("C"); // 4

After method m1 returns, the object created on which line is not eligible for garbage collection?

In this //1 is the answer'

How is this , in the first line actually we create an array of size 3 that can hold types of I and in consutive lines we add the reference information to array. Can anybody explain whats happening in the //1 line

Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The object on line 1 is an array object. So even if you make the individual objects null, the actual array object is not null

Hope that helps

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic