| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:[求助]一个缠了我好久的问题~
只看楼主 加入收藏
snakealpha
Rank: 1
来 自:扬州
等 级:新手上路
威 望:1
帖 子:267
专家分:0
注 册:2005-11-5
收藏
 问题点数:0 回复次数:0 
[求助]一个缠了我好久的问题~
发在博客上没人理,所以转发在这里~~~

以下代码:

Imports Microsoft.VisualBasic
Imports system


Public Class hello
Private myName As String
Public Sub New(ByVal name As String)
myname = name
console.writeline("Hello,{0}!", name)
End Sub
Protected Overrides Sub finalize()
console.writeline("GoodBye,{0}!", myname)

End Sub

End Class
Public Class application
Public Shared Sub main()
Dim i As Integer
For i = 1 To 5
Dim hello As New hello(i.tostring)
Next i

End Sub
End Class

得到结果:

Hello,1!
Hello,2!
Hello,3!
Hello,4!
Hello,5!
GoodBye,5!
GoodBye,1!
GoodBye,4!
GoodBye,3!
GoodBye,2!

书上解释为:

"看起来对象似乎是按照与创建对象相反的顺序释放的,表明是插入到了一个堆栈是的结构中.事实上这就是所发生的事情."(VisualBasic.Net面向对象编程,J.P.Hamilton)

但是以下例子:

Imports Microsoft.VisualBasic
Imports system


Public Class hello
Private bigchunkomemory(10000) As Byte
Private myName As String
Public Sub New(ByVal name As String)
myname = name
console.writeline("Hello,{0}!", name)
End Sub
Protected Overrides Sub finalize()
console.writeline("GoodBye,{0}!", myname)

End Sub

End Class
Public Class application
Public Shared Sub main()
Dim i As Integer
For i = 1 To 10000
Dim hello As New hello(i.tostring)

Next i

End Sub
End Class

输出的结果中有一段:

Hello,112!
Hello,113!
Hello,114!
Hello,115!
GoodBye,101!
GoodBye,15!
GoodBye,14!
GoodBye,13!

另一段:

GoodBye,3!
GoodBye,2!
GoodBye,1!
GoodBye,100!
GoodBye,99!
GoodBye,98!
GoodBye,97!

怎么会15~1会比100先释放呢?如果如书上说是“堆栈”的话?

2007-08-26 16:13
快速回复:[求助]一个缠了我好久的问题~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015829 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved