# Revision history [back]

### Opencv fails to allocate memory

Hello,

In part of my code I am doing this!

// LONG_HIST, etc. are pre-defined
// getHistoryLong() etc. return IplImage*


The reason I am cloning the image is that if I don't and simply dereference it, after stack call is returned, the information is gone! I mean partially. Because it turns out that when I am trying to fetch the saved values back into the main application It is having access violation errors.

This solves the problem except the fact that now I am getting memory allocation failures from OpenCV. I believe that using cvCloneImage() I am making too many calls to malloc but not freeing the memory correctlyl. However, I might be wrong. Shall I store it as OpenCV and load it as IplImage* pointer to be safe?

### Opencv fails to allocate memory

Hello,

In part of my code I am doing this!

// LONG_HIST, etc. are pre-defined
// getHistoryLong() etc. return IplImage*


The reason I am cloning the image is that if I don't and simply dereference it, after stack call is returned, the information is gone! I mean partially. Because it turns out that when I am trying to fetch the saved values back into the main application It is having access violation errors.

This solves the problem except the fact that now I am getting memory allocation failures as:

OpenCV Error: Insufficient Memory (failed to allocate xyz bytes) in unknown function, file
..\..\opecv\modules\core\src\alloc.cpp line 52.


from OpenCV. I believe that using cvCloneImage() I am making too many calls to malloc but not freeing the memory correctlyl. However, I might be wrong. Shall I store it as OpenCV and load it as IplImage* pointer to be safe?

### Opencv fails to allocate memory

Hello,

In part of my code I am doing this!

// LONG_HIST, etc. are pre-defined
// getHistoryLong() etc. return IplImage*
myMasks.clear(); // Clear so that we only have one set at a time.


The reason I am cloning the image is that if I don't and simply dereference it, after stack call is returned, the information is gone! I mean partially. Because it turns out that when I am trying to fetch the saved values back into the main application It is having access violation errors.

This solves the problem except the fact that now I am getting memory allocation failures as:

OpenCV Error: Insufficient Memory (failed to allocate xyz bytes) in unknown function, file
..\..\opecv\modules\core\src\alloc.cpp line 52.


from OpenCV. I believe that using cvCloneImage() I am making too many calls to malloc but not freeing the memory correctlyl. However, I might be wrong. Shall I store it as OpenCV and load it as IplImage* pointer to be safe?

### Opencv fails to allocate memory

Hello,

In part of my code I am doing this!

// LONG_HIST, etc. are pre-defined
// getHistoryLong() etc. return IplImage*
myMasks.clear(); // Clear so that we only have one set at a time.


My image processing application is such that when I detect a certain event, I store the mask information of my current scene using a method called updateMasks() which, in essence, does the above. However, I only update the images only once. I have also in place a flag called "savedMasks" and this is what i do when I save the masks to my current scene object:

if(currentSceneObject->getSaveMasks == true) {
currentSceneObject->setSaveMasks == false; // clear the flag
}


If my understand is correct, It will only save it once, but not multiple times.

__WHY AM I CLONING OR DEEP COPYING THE IplImage*(s)__

The reason I am cloning the image is that if I don't and simply dereference it, after stack call is returned, the information is gone! I mean partially. Because it turns out that when I am trying to fetch the saved values back into the main application It is having access violation errors.

This solves the problem except the fact that now I am getting memory allocation failures as:

OpenCV Error: Insufficient Memory (failed to allocate xyz bytes) in unknown function, file
..\..\opecv\modules\core\src\alloc.cpp line 52.


from OpenCV. I believe that using cvCloneImage() I am making too many calls to malloc but not freeing the memory correctlyl. However, I might be wrong. Shall I store it as OpenCV and load it as IplImage* pointer to be safe?