views:

21

answers:

0

I'm using VB.NET for a small control software which analyzes the messages of a video router. I need to hook up to the DLL (which includes the needed interface to the router) using WndProc. Everything was running smoothly in the Lab, but on site (where the router sends more messages) I get a huge memory leak (inside the unmanaged heap).

This is my code:

Protected Overrides Sub WndProc(ByRef m As Message)

    Do Until msg_read_empty
        If msg_read(id, buffer) Then

            filter_msg(id, buffer)

        End If

     Loop

    MyBase.WndProc(m)

End Sub

AS you see - very simple. id is an Int, buffer is an Object. msg_read_empty() and msg_read() are API calls.

The Sub filter_msg() filters all the messages and processes them.

The memory leak must be caused by that, since this doesn't happen when I comment out those lines... To complete my post, here's the method:

Public Sub filter_DMS(ByRef zd As Integer, ByRef buffer As Object)

    filter_id = Hex(zd)
    filter_value = buffer.ToString

    If filter_id = SETCP1 And filter_value = "1" Then

       ' perform some actions '

    ElseIf filter_id = SETCP2 And filter_value = "1" Then

        '...'

    ElseIf filter_id = SETTINGS And filter_value = "1" Then

        '...'

    ElseIf filter_id = CONTROL And filter_value = "1" Then

        '...'

    Else

        '..'

    End If

End Sub

I have removed the code inside the if statement, but they don't cause the memory leak for sure. Would you rather use a 'Select Case' statement for that "filtering"?