Originally posted by Angela Jessi:
How Can I setup manual Garbage Collection? What is difference between GC method and runFinalization and Finalize. I need three of them OR either of them?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"JavaRanch, where the deer and the Certified play" - David O'Meara
"JavaRanch, where the deer and the Certified play" - David O'Meara
Originally posted by srinivas mand:
what is the runfinalization() for??
Originally posted by Angela Jessi:
In Our project, we want to run garbage collection manually at specific location i mean when some objects we have set to NULL.
Originally posted by Cindy Glass:
Actually when you set the variables to null and release all of the references to the object the garbage collector should run WITHOUT you having to call it. Like magic .
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
"I'm not back." - Bill Harding, Twister
Originally posted by Joel McNary:
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
"I'm not back." - Bill Harding, Twister
Originally posted by Joel McNary:
[B]
fo2 might be null, fo1 is definitly null. line 310 only makes it explicit.
[/B]
Agreed - we don't know what fo2 is pointing at. Like C pointers, it could be pointing either at memory address 0x0000000 or to some random point in memory. Of course, Java hides the memory locations from us, so all we know is that we have a reference to an object of type Foo. Until we explicitly initialize it, however, the compiler assumes that whatever might be on the other end of the reference (including null) is invalid. So, if we try to use it before initializing it, the compiler will let us know.
Mixing in Concepts of C is not very helpful.
Especially the distinction between 'reference to an object' and 'object' doesn't seem to be common to me.
[B]
f1 is an object, while f2 isn't?
That's new to me.
In Line 530, how can you distinguish f1 from f2? What is the diffence?
[/B]
f1 and f2 are both references to Foo objects. While in general parlance we can refer to them as Objects themselves, that's not really what's going on. f1 "points" to a Foo object in the heap, and then f2 "points" to that same object. You can't really tell the difference between the references;
they will work the same. But they are both references, not an Object and a Reference.
[B]
f1 IS A OBJECT. You may call it a reference to an object but my experiences with talking about concepts and elements of Java is, that usually you call f1 an object.
If you have pointers like in C++, you may need a distinction between pointers and references, but you needn't import this distinction to Java, because we have no pointers.
In my Opinion both are objects (f2 and f1), (in this case: the same object). You may call it references - and from time to time I do it myself - but you cannot say, that "that's not what's really going on".
You say 'f1 points to a Foo object in the heap' - so if you think there is a foo-object on (or in) the heap, let's call it f1 , because that's it's name.
[b]
Suppose following class:
(Lines 8.*0 are formerly known as 8.*)
If someone calls Gooz.gooz (), Object f is created in Line 8360, a Foo, which contains 2 Bars.
In Line 8364 it is set to null, but might not be gc-ed - it is needed in Line 8368 again.
In Line 8380 this Foo f runs out of scope, and might be gc-ed.
It cannot be referenced from anywhere.
Those Bars b1, b2 are ready for gc too.
[/B]
Remember, the reference is not the object.
On line 83600, an Object is created which ontains two Bars.
YES, yes, yes
On line 83640, the reference to that object is lost; so the object may now be gc'ed.
No. the two Bars inside the object may be gc-ed, because there is no reference which can reach them.
I introduced some new lines to make my point clearer. (pleased to meet you...)
My object g in 83605 is the same object like f.
Perhaps it's a Pointer at adress 0x8000, pointing to 0x47900, where f is. f itself contains those bars,
so at 0x47950 might be a reference to b1 which is at 0x8500, and at 0x47970 a reference to b2 ...
I guess, that in line 83680, where a new Foo is assigned to f, the adress of f (0x8000) is still the same, but might point to another location - let's say 0x8100.
Now my object g comes to the scene. g was told to be f. Will line 83705 work? (Yes, I tested it.)
I guess we don' t differ to much, in what we believe what is happening, but how to express this.
Since you don't work directly with objects but instead manipulate them through reference to those objects, you simnple can't do things like this in Java--it doesn't make syntactic sense.
Originally posted by Jim Yingst:
One other point I haven't seen addressed (though I might've missed it):
No, there's no way this could throw a NullPointerException, regardless of whether s was null or not. The reference s is definitely there; it hasn't been garbage collectied or anything - it's a varable which may be assigned a value. In this case, it's being assigned the value of a reference to the "Am I null" object.
So therefore I wrote 'WOULD have been bad'.
Since the gc will not run, we cannot figure out, whether this could throw a NullPointerException, and therefore you' re right.
But is "Am I null" an object? In my opinion: no.
It's a literal constant. It has no methods and no attributes. It's just values. Only in conjunction with 's' we can talk about an Object.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
"I'm not back." - Bill Harding, Twister
Originally posted by Joel McNary:
In line 83645, you state that "g is null too." This, I think, is the source of the confusion. At this point in the code, g is not null. g is still pointing to the same object that f was originally pointing to. (Thereby ensuring that the object will not be garbage collected, since there is a reference to it.) The call to g.foo() will be called on the Foo object created in line 83600, not the one in line 83680.
Of course you're right.
Shame on me!
It's so obvious!
But I was very sure while writing this down.
Perhaps this happened because I compared references with symbolic links in the linux file-system. This comparison went too far .
Thanks to your endurance.
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|