Loading...

Memmory issue with GDViewer 4 OCX

Support for GdViewer OCX and GdViewer Pro ActiveX/SDK.

Memmory issue with GDViewer 4 OCX

Postby Donleary » Tue Oct 06, 2009 7:24 pm

Hello,
we are having issues with the GD viewer (version 4) not releasing memmory when CloseImage() is called.
we are currently using the viewer to diplay frames from a USB CMOS camera, each frame is recieved as raw image data then constructed into a bitmap. the problem is when CloseImage() is called memmory is not getting released (page file increases to the point that the GD viewer window goes blank), i have concluded this by just displaying the image in a standard picturebox control, which works fine. the code i am using is below:

Code: Select all
Private Sub DrawImage()

        If IS_Drawing Then Exit Sub

        IS_Drawing = True

        ' get geometry of image buffer
        Dim width As Integer = 0, height As Integer = 0, bitspp As Integer = 0, pitch As Integer = 0, bytespp As Integer = 0

        Dim imagesize As Long = 0
        m_uEye.InquireImageMem(m_pCurMem, GetImageID(m_pCurMem), width, height, bitspp, pitch)

        bytespp = (bitspp + 1) / 8

        imagesize = width * height * bytespp

        ' image size in bytes
        Dim MyBitmap As Bitmap

        ' bulit a system bitmap
        MyBitmap = New Bitmap(width, height, PixelFormat.Format24bppRgb)

        ' fill the system bitmap with the image data from the uEye SDK buffer
        Dim bd As BitmapData = MyBitmap.LockBits(New Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)

        m_uEye.CopyImageMem(m_pCurMem, GetImageID(m_pCurMem), bd.Scan0)

        MyBitmap.UnlockBits(bd)

        Image_Exists = True

   
         Try

            Me.DisplayWindow.CloseImage()
            Me.DisplayWindow.DisplayFromStdPicture(MyBitmap)
'the page file sizes increases to the point of the app crashing
        Catch ex As Exception

        End Try

     
        IS_Drawing = False

    End Sub


any help will be appreciated, thank you,
don
Donleary
 
Posts: 4
Joined: Wed Dec 31, 2008 1:03 am

Re: Memmory issue with GDViewer 4 OCX

Postby Loïc » Tue Oct 06, 2009 8:01 pm

Hi,

The DisplayFromStdPicture() should not be used with a .NET Bitmap or Image but with an OLE picture.

To be honest, I don't understand why Visual Studio dotnet allows to do that.

However, I am quite sure your problem can be solved with a simple release of your original bitmap.:

Code: Select all
MyBitmap.Dispose


Or use the DisplayFromHBitmap() method using MyBitmap.GetHbitmap as parameter.

With best regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Memmory issue with GDViewer 4 OCX

Postby Donleary » Tue Oct 06, 2009 9:02 pm

yes, i did try releasing the bitmap prior to this thread, but in theory that is what the .net GC handles once the sub routine is exited (which isnt the best practice at all). i tried implimenting what you have suggested and it rendered the same results, page file just climbed to the point of a memory dumb and program crash:

Me.DisplayWindow.CloseImage()
Me.DisplayWindow.DisplayFromHBitmap(MyBitmap.GetHbitmap)
MyBitmap.Dispose()
bd = Nothing

any other suggestions Loïc?
thank you kindly,
don
Donleary
 
Posts: 4
Joined: Wed Dec 31, 2008 1:03 am

Re: Memmory issue with GDViewer 4 OCX

Postby Donleary » Tue Oct 06, 2009 9:31 pm

please disregard the last post, the issue has been resolved. i was not disposing of the pointer after use:

Dim BMP_PTR As New IntPtr
BMP_PTR = MyBitmap.GetHbitmap()
Me.DisplayWindow.CloseImage()
Me.DisplayWindow.DisplayFromHBitmap(BMP_PTR)
MyBitmap.Dispose()
bd = Nothing
DeleteObject(BMP_PTR)

all works fine, thank you for your speedy response. we currently have a project that is being sold with the GD Viewer and one of the examples stated to use what i first posted "DisplayFromStdPicture" passing it a standard .net bitmap, your saying this could cause issues? now that i think of it there have been several reports of out of memory... do you recomend changing this to "DisplayFromHBitmap"?

thank you,
don
Donleary
 
Posts: 4
Joined: Wed Dec 31, 2008 1:03 am

Re: Memmory issue with GDViewer 4 OCX

Postby Loïc » Tue Oct 06, 2009 9:37 pm

Okay thanks for the feedback.

Yes, I suggest to use DisplayFromHBitmap instead DisplayFromStdPicture. Again, I don't understand why a .NET Bitmap can be used as OLEBitmap parameter... :|
In a future version of Visual Studio you will maybe unable to keep this "implicit conversion".

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France


Return to GdViewer [Pro] ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest