I wrote a plugin in the form of a registered C# class library which has COM exposed methods.
Static objects in the class seem to survive between calls of Sub Main
.
Why is that? Can I prevent it and completely 'reload/restart' the library?
(I did set the ctrPlugin
object to Nothing
)
From VBA, I instantiate classes and call methods from the C# library like this:
Option Explicit
Sub Main
Dim ctrPlugin
Set ctrPlugin = CreateObject("MyLibrary.MyExposedClassName")
ctrPlugin.OpenWpfWindowMethod
Set ctrPlugin = Nothing
End If
End Sub
The problem I'm having with it, is an occasional "Out of memory" error. Which is shown in the host application (an ERP system) after the c# method is completed. The error never shows while running a c# method, always after it completed. I never have these issues when I work with C# applications. Is there a difference between object lifetimes and garbage collecting processes between C# application and class library?
I already memory profiled my library in visual studio, and got rid of some memleaks. (One of which was caused by WPF bindings to objects which weren't DependencyObjects or inherited INotifyPropertyChanged)
question from:
https://stackoverflow.com/questions/65941614/why-do-static-variables-in-a-c-sharp-class-library-survive-across-object-instant 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…