Do you actually run out of memory, or are you simply seeing usage
increase?
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
I perform a dispose on myBmp and I dispose also myHdc.
Complete Code:
// Constructor
public NDImager()
{
// Get form handle
myHandle = GetActiveWindow();
if (myHandle != IntPtr.Zero)
{
// get handle device context
myHdc = OpenNETCF.Win32.Core.GetDC(myHandle);
// build a NDImagerMessageWindow object
myMsgWnd = new NDImagerMessageWindow(this);
}
}
// An other Method which used myBmp, myHdc ...
// this code is in a switch
// I think it's here there is a problem with memory
// get an handle to a bitmap
IntPtr hBitmap;
hBitmap = NDCaptureUtility.CreateGreyImageInDeviceContext(myHdc);
// delete last bitmap
if (myBmp != null)
{
myBmp.Dispose();
myBmp = null;
}
// if handle is not null
if (hBitmap != IntPtr.Zero)
{
// create bitmap with an handle
myBmp = NDBitmapBuffer.FromHbitmap(hBitmap);
// display bitmap
myPictureBox.Image = myBmp;
myPictureBox.Invalidate();
// delete handle (unmanaged ressource)
// the value which is returned by closehandle is false that's why I use
DeleteObject
DeleteObject(hBitmap);
}
protected void Dispose(bool disposing)
{
if (disposing)
{
// Stop Window Message
StopRunningWithMessageWnd();
Thread.Sleep(500);
// Remember to release the device context
OpenNETCF.Win32.Core.ReleaseDC(myHandle, myHdc);
myHdc = IntPtr.Zero;
if (myBmp != null)
{
myBmp.Dispose();
myBmp = null;
}
// Dispose Message Manager
myMsgWnd.Dispose();
myMsgWnd = null;
}
}
Do you have an idea with all code ?
Thanks
Best Regards
:
Are you ever disposing myBmp? Are you ever actually running out of
memory?
-Chris
Hi Alex, Hi Sergey
yes I can show my code of course.
[DllImport("coredll.dll", SetLastError=true)]
public static extern bool CloseHandle(IntPtr hObject);
...
// get an handle to a bitmap
IntPtr hBitmap;
hBitmap = NDCaptureUtility.CreateGreyImageInDeviceContext(myHdc);
....
// create bitmap with an handle
myBmp = BitmapBuffer.FromHbitmap(hBitmap);
...
// delete handle (unmanaged ressource) with close handle
CloseHandle(hBitmap); // the value which is return is false
// That's why I used DeleteObject
DeleteObject(hBitmap);
But when I analyse Memory with Majerus's tools (
www.phm.lu), I can
see
the
memory is more and more used.
I think my problem is hBitmap.
CreateGreyImageInDeviceContext is a method which is in a C Dll.
There
are
some methods which send some messages and with methods I can perform
a
preview and I can take some pictures. Maybe a problem with unmaneged
Window
Message ? I know also compact framework service pack 3 which correct
some
bugs with the marshalling between C# and C
What do you think about this ?
Thanks
Best Regards.
Fred
:
Which handle are you trying to de-allocate?
Could you show your code?
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com |
www.opennetcf.org
:
Hi,
I have an handle on a bitmap (FromHBitmap by Alex Yakhnin).
I'd like to close this handle with CloseHandle Method in core.dll
but
it
seems to me that method has no effect.
I use DeleteObject but it seems to me there are small memory
leaks...
How can I do ?
Thanks
Best Regards