03-28-2018
10:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-28-2018
10:01 PM
Example: I put this code into a rule, and when it runs, the last message box says than n_ is 3. It seems like it should be zero at that point. The messages in the Finalize method never display. It seems like one or the other of them should display 3 times. I have a bigger project, and classes that unload files in their destructor. Those destructors never ran until I put a Save (to disk) function in my code before the objects go out of scope. Then the destructors mostly started running. Why would it be inconsistent like that?
SyntaxEditor Code Snippet
ublic Class ThisRule Public Sub Main() Dim a As New Counted Dim b As New Counted MsgBox("creating a") a = Nothing MsgBox("a destroyed") f() MsgBox("f returned") b = Nothing MsgBox("b destroyed") MsgBox("n=" & Counted.n_.ToString()) End Sub Public Sub f() Dim c As New Counted End Sub End Class Public Class Counted Public Shared n_ As Integer = 0 Public Sub New() n_ = n_ + 1 End Sub Public Sub Finalize() n_ = n_ - 1 If n_ = 0 Then MsgBox("Destroyed!") Else MsgBox("Not Destroyed") End if End Sub End Class