Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. memory usage keeps going up when retrieving webcam image

memory usage keeps going up when retrieving webcam image

Scheduled Pinned Locked Moved C / C++ / MFC
c++javadelphidatabaseperformance
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khrstopher
    wrote on last edited by
    #1

    I've written a JAva program that uses JNI to call some C++ methods to retrieve webcam images using video for windows. The problem is that every time I retrieve an image, memory usage keeps going up. I'm still a noob to C++ so the problem may be something really simple. Here's my code: code: HWND m_capWindow; int connectedIndex; LRESULT PASCAL callbackProc(HWND hWnd, LPVIDEOHDR lpVHdr); LRESULT PASCAL callbackProc(HWND hWnd, LPVIDEOHDR lpVHdr) { return 0; } JNIEXPORT void JNICALL Java_client_desktop_dateclick_Test_connect (JNIEnv *, jobject, jint index) { m_capWindow = capCreateCaptureWindow ("", WS_CHILD, 0, 0, 0, 0, GetDesktopWindow(), 10); //m_capWindow = capCreateCaptureWindow ("Capture", WS_CHILD | WS_VISIBLE, 50, 50, 480, 360, GetDesktopWindow(), 10); // connect to the new driver BOOL rval = capDriverConnect (m_capWindow, index); capSetCallbackOnFrame(m_capWindow, callbackProc); capPreview(m_capWindow, FALSE); } JNIEXPORT jbyteArray JNICALL Java_client_desktop_dateclick_Test_getImage (JNIEnv *env, jobject) { CString fileName; int contentLength; BYTE *frame; capGrabFrame(m_capWindow); //capGrabFrameNoStop(m_capWindow); fileName = "capframe.bmp"; //and use this file... capFileSaveDIB( m_capWindow, (LPCTSTR)fileName); CFile jpegTemp; // now read the resulting file into a buffer jpegTemp.Open("capframe.bmp", CFile::modeRead); contentLength = (UINT)jpegTemp.GetLength(); //allocate the buffer for the jpeg frame frame = new BYTE[contentLength]; //now read in the jpeg file jpegTemp.Read(frame, contentLength); jpegTemp.Close(); jbyteArray ba = env->NewByteArray(contentLength); env->SetByteArrayRegion(ba, 0, contentLength, (jbyte*) frame); delete frame return ba; } JNIEXPORT void JNICALL Java_client_desktop_dateclick_Test_disconnect (JNIEnv *env, jobject) { capDriverDisconnect(m_capWindow); }

    M 1 Reply Last reply
    0
    • K khrstopher

      I've written a JAva program that uses JNI to call some C++ methods to retrieve webcam images using video for windows. The problem is that every time I retrieve an image, memory usage keeps going up. I'm still a noob to C++ so the problem may be something really simple. Here's my code: code: HWND m_capWindow; int connectedIndex; LRESULT PASCAL callbackProc(HWND hWnd, LPVIDEOHDR lpVHdr); LRESULT PASCAL callbackProc(HWND hWnd, LPVIDEOHDR lpVHdr) { return 0; } JNIEXPORT void JNICALL Java_client_desktop_dateclick_Test_connect (JNIEnv *, jobject, jint index) { m_capWindow = capCreateCaptureWindow ("", WS_CHILD, 0, 0, 0, 0, GetDesktopWindow(), 10); //m_capWindow = capCreateCaptureWindow ("Capture", WS_CHILD | WS_VISIBLE, 50, 50, 480, 360, GetDesktopWindow(), 10); // connect to the new driver BOOL rval = capDriverConnect (m_capWindow, index); capSetCallbackOnFrame(m_capWindow, callbackProc); capPreview(m_capWindow, FALSE); } JNIEXPORT jbyteArray JNICALL Java_client_desktop_dateclick_Test_getImage (JNIEnv *env, jobject) { CString fileName; int contentLength; BYTE *frame; capGrabFrame(m_capWindow); //capGrabFrameNoStop(m_capWindow); fileName = "capframe.bmp"; //and use this file... capFileSaveDIB( m_capWindow, (LPCTSTR)fileName); CFile jpegTemp; // now read the resulting file into a buffer jpegTemp.Open("capframe.bmp", CFile::modeRead); contentLength = (UINT)jpegTemp.GetLength(); //allocate the buffer for the jpeg frame frame = new BYTE[contentLength]; //now read in the jpeg file jpegTemp.Read(frame, contentLength); jpegTemp.Close(); jbyteArray ba = env->NewByteArray(contentLength); env->SetByteArrayRegion(ba, 0, contentLength, (jbyte*) frame); delete frame return ba; } JNIEXPORT void JNICALL Java_client_desktop_dateclick_Test_disconnect (JNIEnv *env, jobject) { capDriverDisconnect(m_capWindow); }

      M Offline
      M Offline
      MF
      wrote on last edited by
      #2

      Memory Leakage is caused by

      khrstopher wrote:

      delete frame;

      you should use delete []frame; :omg:

      S 1 Reply Last reply
      0
      • M MF

        Memory Leakage is caused by

        khrstopher wrote:

        delete frame;

        you should use delete []frame; :omg:

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        If he's using any of the MSVC compilers I've worked with this will not result in a leak - It's wrong but it doesn't result in a memory leak. Steve

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups