Problem with iterating over a lots of images in OpenCv

I'm trying to iterator over some directories containing approximately 3000 images. I load the image. If the image is loaded I release it. 
That is the smallest program that I can write to reproduce the error. 

After loading and releasing 124 images the program stops loading images. I think this a **memory** issue but I don't understand what exactly causes the program to stop loading images. 

I'm using **OpenCV** on my **Mac**. I don't know how exactly I can figure out which version I'm using. 

Here is the Code from my project.

    bool FaceDetectionStrategy::detectFace(std::string imagePath) {

       IplImage *img = cvLoadImage(imagePath.c_str(), CV_LOAD_IMAGE_COLOR);
       if (img) {
          std::cout << "Image loaded " << imagePath << std::endl;
          cvReleaseImage(&img);
       } else {
          std::cout << "Image not loaded " << imagePath << std::endl;
       }
    return true;
}

This method is called for every image in the directorys I'm iterating through. After 124 images the if(img) part evaluates to false and the else branch is executed. If I try to load images from other parts of the program later on they also want load.
Problem with iterating over a lots of images in OpenCv
===


I'm trying to iterator over some directories containing approximately 3000 images. I load the image. If the image is loaded I release it. 
That is the smallest program that I can write to reproduce the error. 

After loading and releasing 124 images the program stops loading images. I think this a **memory** issue but I don't understand what exactly causes the program to stop loading images. 

I'm using **OpenCV** on my **Mac**. I don't know how exactly I can figure out which version I'm using. 

Here is the Code from my project.

    bool FaceDetectionStrategy::detectFace(std::string imagePath) {

       IplImage *img = cvLoadImage(imagePath.c_str(), CV_LOAD_IMAGE_COLOR);
       if (img) {
          std::cout << "Image loaded " << imagePath << std::endl;
          cvReleaseImage(&img);
       } else {
          std::cout << "Image not loaded " << imagePath << std::endl;
       }
    return true;
}

This method is called for every image in the directorys I'm iterating through. After 124 images the if(img) part evaluates to false and the else branch is executed. If I try to load images from other parts of the program later on they also want load.