About memory management in OpenCV

I'm sorry if this may seem like a silly question... I've a doubt about cvLoadImage in OpenCV:

IplImage *frame;
for (unsigned int i = 0; i < LENGTH; i++)
{
    frame = cvLoadImage(filename.c_str());  
    // do something...
}

For each call of cvLoadImage is a new IplImage stored in memory? Is the old variable pointed by frame released from heap after the override?

Furthermore, when I try to release an image as follow...

IplImage *frame;
for (unsigned int i = 0; i < LENGTH; i++)
{
    if (frame != NULL)
        cvReleaseImage(&frame);

    frame = cvLoadImage(filename.c_str());  
    // do something...
}

Why doesn't this solution work (bad memory access)? Best regards, Vi.

Answers


Yes, memory allocated by cvLoadImage. Error appears because you not initialized frame in the beginning. It must be initialized by zero, or NULL.


Need Your Help

Prevent Int From Being Subtracted

java int subtract

Is it possible to prevent an int from being subtracted from? The final keyword wouldn't work here, as I still need to be able to add to it. Thanks!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.