Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3437092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:01:22+00:00 2026-05-18T08:01:22+00:00

Even just doing the most basic video streaming causes a memory leak for me.

  • 0

Even just doing the most basic video streaming causes a memory leak for me.

cvNamedWindow("1",0);
CvCapture *fc = cvCaptureFromCAM(0);
IplImage *frame = NULL;
CvSize frameSize;
frameSize.height = cvGetCaptureProperty(fc, CV_CAP_PROP_FRAME_HEIGHT);
frameSize.width = cvGetCaptureProperty(fc, CV_CAP_PROP_FRAME_WIDTH);

while (1) { 
    IplImage *wrkImage = NULL;

    frame = cvQueryFrame(fc);

    if (!frame) 
        break;

    wrkImage = cvCreateImage(frameSize, IPL_DEPTH_8U, 3);
    cvCopy(frame, wrkImage, NULL);

    cvShowImage("1", wrkImage);

    char c = cvWaitKey(33);
    if (c == 27) {
        break;
    }

    cvReleaseImage(&wrkImage);
}

Apparently according to the book “Learning OpenCV”, I’m not supposed to release “frame” since it’s managed by openCV and I can “expect problems if I do”. It does indeed cause problems if I release the frame pointer once I’ve called cvQueryFrame. The book also suggests copying the image pointed to by cvQueryFrame elsewhere to work on it since cvQueryFrame presumably recycles the same chunk of memory repeatedly. Hence wrkImage which I do release at the end of each frame cycle. The program crashes after a few mins, and leaks memory like crazy! Leads me to believe something major is getting leaked like entire frames. I’m wondering if anyone uses OpenCV 2.1 on the Mac for video stuff and has found this to be an issue as well. Or if anyone can see a gaping hole in my code that I’m missing.

Any advice from OpenCV guru’s out there would be much appreciated!

Edit: After carefully stepping through the program and examining memory, I suspect the issue is with cvShowImage(). cvShowImage seems to allocate about a frame’s worth of memory that never seems to get reclaimed. Then found this link OpenCV cvShowImage Memory Leaks OSX that seems to agree with my suspicions. Might be close to a solution here… Just glad to see I’m not crazy!

UPDATE: The Macports OpenCV is fine now (and has been for a few months now. Just thought I should post that here so people aren’t getting discouraged from using macports for their OpenCV build/install. Macports is a great way to install OpenCV.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:01:23+00:00Added an answer on May 18, 2026 at 8:01 am

    There is nothing wrong with the code I provided. The current MacPorts build of openCV has a memory leak in the cvShowImage() function. I downloaded and built the most recent version manually, and it no longer leaks memory.

    For anyone who reads this, if your openCV program is curiously leaking memory, and you installed using MacPorts, I’d suggest downloading the source and building manually using cmake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.