— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

An instance variable and 
a local variable discuss life and death 
(with remarkable civility)


constructors and 
gc
you are here
4
265
We saw an educational video about it once. 
Looks like a pretty brutal ending. I mean, 
when that method hits its ending curly brace, 
the frame is literally blown off the Stack! Now 
that’s gotta hurt.
I live on the Heap, with the objects. Well, not 
with the objects, actually in an object. The 
object whose state I store. I have to admit life 
can be pretty luxurious on the Heap. A lot of 
us feel guilty, especially around the holidays.
OK, hypothetically, yes, if I’m an instance 
variable of the Collar and the Collar gets 
GC’d, then the Collar’s instance variables 
would indeed be tossed out like so many pizza 
boxes. But I was told that this almost never 
happens.
They let us drink
frame gets to run again. On the one hand, we 
get to be active again. On the other hand, the 
clock starts ticking again on our short lives. 
The more time our method spends running, 
the closer we get to the end of the method. 
We all know what happens then.
Tell me about it. In computer science they use 
the term popped as in “the frame was popped 
off the Stack”. That makes it sound fun, or 
maybe like an extreme sport. But, well, you 
saw the footage. So why don’t we talk about 
you? I know what my little Stack frame looks 
like, but where do you live?
But you don’t always live as long as the object 
who declared you, right? Say there’s a Dog 
object with a Collar instance variable. Imagine 
you’re an instance variable of the Collar object, 
maybe a reference to a Buckle or something, 
sitting there all happy inside the Collar object 
who’s all happy inside the Dog object. But... 
what happens if the Dog wants a new Collar, 
or nulls out its Collar instance variable? That 
makes the Collar object eligible for GC. So... 
if you’re an instance variable inside the Collar, 
and the whole Collar is abandoned, what 
happens to you?
And you believed it? That’s what they say to 
keep us motivated and productive. But aren’t 
you forgetting something else? What if you’re 
an instance variable inside an object, and that 
object is referenced only by a local variable? If 
I’m the only reference to the object you’re in, 
when I go, you’re coming with me. Like it or 
not, our fates may be connected. So I say we 
forget about all this and go get drunk while 
we still can. Carpe RAM and all that.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   252   253   254   255   256   257   258   259   ...   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