— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet257/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   253   254   255   256   257   258   259   260   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Instance Variable
Local Variable


266
 
chapter 9
Which of the lines of code on the right, if added 
to the class on the left at point A, would cause 
exactly one additional object to be eligible for the 
Garbage Collector? (Assume that point A (//call 
more methods) will execute for a long time, giving the 
Garbage Collector time to do its stuff.)
Exercise
BE the Garbage Collector
public class GC {
public static GC doStuff() {
GC newGC = new GC();
doStuff2(newGC);
return newGC;
}
public static void main(String [] args) {
GC gc1;
GC gc2 = new GC();
GC gc3 = new GC();
GC gc4 = gc3;
gc1 = doStuff();
// call more methods
}
public static void doStuff2(GC copyGC) {
GC localGC = copyGC;
}
}
File Edit Window Help Sleep
A
1
2
3
4
5
6
7
8
9
copyGC = null; 
gc2 = null;
newGC = gc3; 
gc1 = null;
newGC = null;
gc4 = null; 
gc3 = gc2;
gc1 = gc4;
gc3 = null; 
exercise: 
Be the Garbage Collector


constructors and 
gc
you are here
4
267
class Bees {
Honey [] beeHA;
}
class Raccoon {
Kit k;
Honey rh;
}
class Kit {
Honey kh;
}
class Bear {
Honey hunny;
}
public class Honey {
public static void main(String [] args) {
Honey honeyPot = new Honey();
Honey [] ha = {honeyPot, honeyPot, honeyPot, honeyPot};
Bees b1 = new Bees();
b1.beeHA = ha;
Bear [] ba = new Bear[5];
for (int x=0; x < 5; x++) {
ba[x] = new Bear();
ba[x].hunny = honeyPot;
}
Kit k = new Kit();
k.kh = honeyPot;
Raccoon r = new Raccoon();
r.rh = honeyPot;
r.k = k;
k = null;
} // end of main
}
Popular 
Objects
In this code example, several new objects are created.
Your challenge is to find the object that is ‘most popular’, 
i.e. the one that has the most reference variables referring 
to it. Then list how many total references there are for 
that object, and what they are! We’ll start by pointing out 
one of the new objects, and its reference variable.
Good Luck !

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   253   254   255   256   257   258   259   260   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish