由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - please help me to solve this question!
相关主题
Skyline跪求大牛指点Java,看不懂什么意思。
a garbage collection questionjava 的函数 xxx(a, b,c)能够向a 写入数据吗?
请教一个javascript的heap的问题。大家在工作中遇到过什么很难的问题(技术上)
看到一个关于singleton的面试题how to use grep/sed to remove newlines? (转载)
Is it possible to get Class object for T from a generic class? (下列空档,是否可填)Re: 有用netbeans的吗?
如何删除 linked list 的最后一个元素where to execute java program?
这种Unit test也有必要吗??Get windows info
CC150 16.6答案是不是有问题? (转载)what's inside an java object?
相关话题的讨论汇总
话题: point话题: rectangle话题: object话题: gc话题: solve
进入Java版参与讨论
1 (共1页)
b*******n
发帖数: 8
1
The following code creates one Point object and one Rectangle object. How many
references to those objects exist after the code executes? Is either object
eligible for garbage collection?
...
Point point = new Point(2,4);
Rectangle rectangle = new Rectangle(point, 20, 20);
point = null;
...
My answer: only one object exists after the code executes. point object is
eligible for garbage collection.
Is my answer right?
w*r
发帖数: 2421
2
nah.. before the GC, theere were 2 objcts, one is the instance of Point
another is the instance of Rect, however, the pint references to null, if
there were not other references to the Point object, that object is eligible
for GC.

many

【在 b*******n 的大作中提到】
: The following code creates one Point object and one Rectangle object. How many
: references to those objects exist after the code executes? Is either object
: eligible for garbage collection?
: ...
: Point point = new Point(2,4);
: Rectangle rectangle = new Rectangle(point, 20, 20);
: point = null;
: ...
: My answer: only one object exists after the code executes. point object is
: eligible for garbage collection.

B******N
发帖数: 445
3
after this code get execute, how many objects eligible for garbage collection
is depending on context.
Let's say if no other object hold reference "point" and "rectangle", then both
eligible for GC. If something hold it like array or vector, then it will not
be GC. IN either case "point = null" makes no difference. So you can remove
it. It's different as c++ "delete".
example:
...
Point point = new Point(2,4);
Rectangle rectangle = new Rectangle(point, 20, 20);
point = null;
mVector.add(point)
.

【在 b*******n 的大作中提到】
: The following code creates one Point object and one Rectangle object. How many
: references to those objects exist after the code executes? Is either object
: eligible for garbage collection?
: ...
: Point point = new Point(2,4);
: Rectangle rectangle = new Rectangle(point, 20, 20);
: point = null;
: ...
: My answer: only one object exists after the code executes. point object is
: eligible for garbage collection.

B******N
发帖数: 445
4
sorry! wrong logic.
I really means this:
...
Point point = new Point(2,4);
Rectangle rectangle = new Rectangle(point, 20, 20);
mVector.add(point):
point = null;
....
in this case point = null dosn't make sure point is GC.
in the original post the "point" is GCed, because the "rectangel" is not
really hold the "point" reference, it just get it's x and y value. It's
different as you put it in an array or vector. Whether the "rectangle" GC
depends on Context.

collection
both
object

【在 B******N 的大作中提到】
: after this code get execute, how many objects eligible for garbage collection
: is depending on context.
: Let's say if no other object hold reference "point" and "rectangle", then both
: eligible for GC. If something hold it like array or vector, then it will not
: be GC. IN either case "point = null" makes no difference. So you can remove
: it. It's different as c++ "delete".
: example:
: ...
: Point point = new Point(2,4);
: Rectangle rectangle = new Rectangle(point, 20, 20);

B******N
发帖数: 445
5
my brain messed up, damn.
I mean GC is eligible for Garbage Collected. Not real time GC. sorry again.

not
remove
this
How

【在 B******N 的大作中提到】
: sorry! wrong logic.
: I really means this:
: ...
: Point point = new Point(2,4);
: Rectangle rectangle = new Rectangle(point, 20, 20);
: mVector.add(point):
: point = null;
: ....
: in this case point = null dosn't make sure point is GC.
: in the original post the "point" is GCed, because the "rectangel" is not

1 (共1页)
进入Java版参与讨论
相关主题
what's inside an java object?Is it possible to get Class object for T from a generic class? (下列空档,是否可填)
How to know the size of a java object ?如何删除 linked list 的最后一个元素
java graphics2d 画图请教这种Unit test也有必要吗??
How to scroll an JInternalFrameCC150 16.6答案是不是有问题? (转载)
Skyline跪求大牛指点Java,看不懂什么意思。
a garbage collection questionjava 的函数 xxx(a, b,c)能够向a 写入数据吗?
请教一个javascript的heap的问题。大家在工作中遇到过什么很难的问题(技术上)
看到一个关于singleton的面试题how to use grep/sed to remove newlines? (转载)
相关话题的讨论汇总
话题: point话题: rectangle话题: object话题: gc话题: solve