Hello
I've had strange memory problem with my application compiled in debug mode.
The problem is that in a visual basic class with an event declaration:
public class Class1
public event Pippo()
end class
in the class, the compiler add this code(I've found it with reflector):
Private Shared __ENCList As List(Of WeakReference)
Shared Sub New()
Class1.__ENCList = New List(Of WeakReference)
End Sub
Public Sub New()
Dim list As List(Of WeakReference) = Class1.__ENCList
SyncLock list
Class1.__ENCList.Add(New WeakReference(Me))
End SyncLock
End Sub
so after each creation of objects, the shared list add an weakreference
item, and never release it...If I need to create thousand and thousand object
of this class, the ram increase and after it goes also to more than 1Gb and
then in outofmemory exception.
Anyway if you compile this code in release mode, or in debug mode but with
"enable optimizations" this strange code disappear...so I resolved it without
big efforts...
But now I would know why the compiler add this weakreference in his shared
list and never remove it...
Thanks