- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created a Finalize method in one of my classes. I instantiate the class in a parameter change rule, so it seems like it should go out of scope after the rule finishes, but the method never executes. Do destructors even work in iLogic classes? Is Finalize the right method name? Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
No speculation, even? Confirmation this happens? Additional information about when it does or doesn't happen, or workarounds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hiya,
In my experience, in a "Try Catch Finally" scenario - the Finally always fires so you could use that instead?
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's an interesting idea. I did discover that Microsoft revised VB so it no longer has destructors! This may help work around. Thanks .for the suggestion.