The problem is that I don't attach anything.
Try this test code pls, so I will be sure that I am not crazy ^^...

Public Class CMyClass
    Inherits Object
    Private fPropertyOne As String
    Private fPropertyTwo As Integer
    Public Event OnSomeEvent(ByRef vSender As Object)
End Class

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn1.Click

        Dim i As Integer
        For i = 0 To 1000
            Dim oEl As New CMyClass()
            Console.WriteLine("element created " &
GC.GetTotalMemory(True))
            oEl = nothing
            Console.WriteLine("element after destroying " &
GC.GetTotalMemory(True))
        Next
    End Sub
End Class

You will find memory growing after any creation. If you cancel event
declaration, you will find that memory get back to the original size
after any creation.
To solve now I try to delegate to a specific object the events, but
it's heavy refactoring and not solve the original problem.
I'm a delphi developer and in Delphi events are property destroyed
when object get free.
I don't understand this way to treat events...

Thank you!

EM

On 24 Set, 12:58, Jamie Fraser <[email protected]> wrote:
> Could you post your code that actually uses that class?
>
> I would assume that you are attaching a listener to this class (or lots of
> instances of this class) and they are of course not being released because
> something is actively attached to them.
>
>
>
> On Wed, Sep 22, 2010 at 11:10 PM, BB <[email protected]> wrote:
> > Hi all,
> > I have a big problem with objects that contain events.
>
> > I found out that my application does not free memory when expected if
> > I use my class as declared:
>
> > Public Class CMyClass
> >    Inherits Object
> >    Private fPropertyOne As String
> >    Private fPropertyTwo  As Integer
>
> >    Public Event OnSomeEvent(ByRef vSender As Object)
>
> > End Class
>
> > Testing with GC, I've got that creating this objects memory grows and
> > do not change when exit from the scope, but if I remove the event
> > declaration, memory get free as I suppose it has to do for the garbage
> > work.
> > The problem is very heavy using many objects like that.
> > I've tried with GC.Collect() but it does not change.
> > Is there something I should know? :(
>
> > I'm using vb.net 2005 with .net 2.0
>
> > Thank you!
>
> > EM

Reply via email to