Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
09-24-2009, 09:52 PM #1
- Join Date
- Sep 2009
- Thanked 0 Times in 0 Posts
.NET memory encreasing (GetBitmapBits)
I am creating an application for my Logitech G19 keyboard with a LCD screen.
First i created a bitmap where i put some information on (such as text) to put on my lcd screen.
Dim bmpNet As Bitmap
...etc...etc... put information, text...etc...
Then, i have to convert the bitmap to bytes/intptr as the following line says with GetBitmapBits:
GetBitmapBits(bmpNet.GetHbitmap, lcdBMPQVGAx32.pixels.Length, lcdBMPQVGAx32.pixels)
Function is declere on top of my source code as:
<DllImport("gdi32.dll", CharSet:=CharSet.Auto, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function GetBitmapBits(ByVal hbmp As IntPtr, ByVal cbBuffer As Integer, ByVal lpvBits As Byte()) As Integer
Now, every time GetBitmapBits invokes, the memory of my application will encrease with 200kB/300kB. I have a timer ticking, so the memory will encrease every, 2 a 3 seconds.
Can someone help me with this problem?
Thanks in advance.
09-24-2009, 11:49 PM #2
- Join Date
- Jun 2002
- Thanked 328 Times in 324 Posts
Well you need to make sure you delete the pointer to the bitmap after you are done with it. So if your timer generates a new bitmap and assigns the new pointer over the old one, you need to take the old pointer and delete it.
That is most likely why you are leaking memory.
However also be aware that you shouldn't be using that GDI function, it is only there for backwards compatibility with 16-bit applications. According to the MSDN this function is the one you should be using: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
Last edited by oracleguy; 09-24-2009 at 11:52 PM.