由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 为什么java没有destructor
相关主题
c++熟手如何学习Java直到能够参与开发企业级应用?对J2EE的几个迷惑 (转载)
有人用过Real Time Java吗?Help!! a cookie question
Java questions 51-100一个JAVA系统的面试问题
GC finalize()一问Wrap up -Re: Question: OutOfMemoryError
JAVA中文TELNET MwTerm 1.000 Final[转载] 现在还有什么OS不是THREAD级调度的吗?
关于运算符的问题请问在Java中有没有停止一切的命令
xp 是不是不支持jave 阿?java编译的文件能不能作成可执行文件?
SCJP都考些啥?入门Java CLASSPATH问题:
相关话题的讨论汇总
话题: gc话题: java话题: destructor话题: finalizer话题: management
进入Java版参与讨论
1 (共1页)
G*O
发帖数: 706
1
这样的设计有什么优缺点?
谢谢!
c*********n
发帖数: 128
2
这是Java著名的特点啊, 任何一本讲Jave的书一开始就会说
因为JVM会自动进行垃圾回收, 这样programmer写程序的时候就不用操心这方面的问题了

【在 G*O 的大作中提到】
: 这样的设计有什么优缺点?
: 谢谢!

c*****t
发帖数: 1879
3
http://en.wikipedia.org/wiki/Destructor_%28computer_science%29
and
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
GC takes care of the biggest pain, the memory management. But by
taking away destructor, one also loses an important pattern for
resource management.
m******d
发帖数: 3243
4
java has finalizer
m******t
发帖数: 2416
5

(I have some vague memory this came up here before.)
With the GC in place, no longer is the destruction of an instance
predictable to the programmer. So any timing-sensitive "resource management"
can't be done in a destructor (or "finalizer" as in Java) anyway. Some kind
of non-standard destroy/release/shutdown method would have to be defined on
a per-class basis.
I see it more as some price paid for all the benefits of GC brings, but not
a loss of any pattern - as long as a pattern can be easi

【在 c*****t 的大作中提到】
: http://en.wikipedia.org/wiki/Destructor_%28computer_science%29
: and
: http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
: GC takes care of the biggest pain, the memory management. But by
: taking away destructor, one also loses an important pattern for
: resource management.

g*****g
发帖数: 34805
6
The Object's finalize method should be avoided.
The time that it will be called is unpredictable,
that alone will give you more hassles than benefits.
There's no timing-sensitive "resource management", we count on
VM to take care of it. If you have a critical application where
response time for every single operation has a bound to be guranteed
and the bound is tight, then Java is not for you.
For that sense, if you are operating a robot on the Moon from the Earth
and every ms delay could put do

【在 m******t 的大作中提到】
:
: (I have some vague memory this came up here before.)
: With the GC in place, no longer is the destruction of an instance
: predictable to the programmer. So any timing-sensitive "resource management"
: can't be done in a destructor (or "finalizer" as in Java) anyway. Some kind
: of non-standard destroy/release/shutdown method would have to be defined on
: a per-class basis.
: I see it more as some price paid for all the benefits of GC brings, but not
: a loss of any pattern - as long as a pattern can be easi

m******t
发帖数: 2416
7
By "timing-sensitive resource management" I was referring to things like
releasing a connection. Those are the things you can't afford to wait for
finalizer.

【在 g*****g 的大作中提到】
: The Object's finalize method should be avoided.
: The time that it will be called is unpredictable,
: that alone will give you more hassles than benefits.
: There's no timing-sensitive "resource management", we count on
: VM to take care of it. If you have a critical application where
: response time for every single operation has a bound to be guranteed
: and the bound is tight, then Java is not for you.
: For that sense, if you are operating a robot on the Moon from the Earth
: and every ms delay could put do

O*******d
发帖数: 20343
8
优点不用说了,缺点之一就是用memory很多.
G*O
发帖数: 706
9
用Dispose interface怎么样?
thanks.

【在 g*****g 的大作中提到】
: The Object's finalize method should be avoided.
: The time that it will be called is unpredictable,
: that alone will give you more hassles than benefits.
: There's no timing-sensitive "resource management", we count on
: VM to take care of it. If you have a critical application where
: response time for every single operation has a bound to be guranteed
: and the bound is tight, then Java is not for you.
: For that sense, if you are operating a robot on the Moon from the Earth
: and every ms delay could put do

m******t
发帖数: 2416
10

It's really not GC that's causing more memory to be used, but rather the
fact that the JVM never returns any memory to the OS, even after the memory
is GC'ed within the VM.

【在 O*******d 的大作中提到】
: 优点不用说了,缺点之一就是用memory很多.
1 (共1页)
进入Java版参与讨论
相关主题
入门Java CLASSPATH问题:JAVA中文TELNET MwTerm 1.000 Final
Java on AIX关于运算符的问题
how to set java run time locale/encoding?xp 是不是不支持jave 阿?
Java program running on PDASCJP都考些啥?
c++熟手如何学习Java直到能够参与开发企业级应用?对J2EE的几个迷惑 (转载)
有人用过Real Time Java吗?Help!! a cookie question
Java questions 51-100一个JAVA系统的面试问题
GC finalize()一问Wrap up -Re: Question: OutOfMemoryError
相关话题的讨论汇总
话题: gc话题: java话题: destructor话题: finalizer话题: management