ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak in imaqFindPattern

Solved!
Go to solution

I suspect a memory leak in imaqFindPattern()

 

When I run this function in a loop the amount of RAM used by the program increases step by step. When I disable two statements in the loop, the amount of RAM used remains the same. The two lines that I toggle are:

 

pm=imaqFindPattern(input_image,ref_image,some_rect,&options,NULL,&n);

if(pm) imaqDispose(pm);

 

I added an 'else' to the 'if', but it is never executed.

It happens also when I use the same image every time in the loop.

 

I used NI Vision 8.6 and CV 8.01 on Windows XP.

 

Please confirm or help. 😉

0 Kudos
Message 1 of 7
(5,272 Views)
Could you please post a copy of the input image, reference image, rectangle, and options you are using?  It will help isolate the problem much more quickly.
Message 2 of 7
(5,262 Views)

These are the options:

 

 // Init FindPattern Options
 IPFindPatternOptions.angleRanges=NULL;
 IPFindPatternOptions.minMatchScore=100;
 IPFindPatternOptions.mode=IMAQ_MATCH_SHIFT_INVARIANT;
 IPFindPatternOptions.numMatchesRequested=1;
 IPFindPatternOptions.numRanges=0;
 IPFindPatternOptions.showResult=FALSE;
 IPFindPatternOptions.showSearchArea=TRUE;
 IPFindPatternOptions.subpixelAccuracy=FALSE;

It's a little bit hard for me to attach pictures, because it is about checking passport images, so personal data is involved.

 

When I run the (very stripped) program below, I do not have a memory leak. 

 

In my original program, when I comment the imaqFindPattern(...) statement there is no leak, when I include it, there is a memory leak.

I have tried the alternative with imaqLearnPattern(...) and imaqMatchPattern(...) but that also leaks.

 

Maybe someone knows about a good memory leak finder (if such exists)?

 

This is the program that does not leak:

 

#include <windows.h>

#include "nivision.h"
#include "nimachinevision.h"

static FindPatternOptions o;

// main
int main(int argc,char *argv[])
{
 Image *SrcImg,*RefImg;
 PatternMatch *pm;
 int i,n;
 
 SrcImg=imaqCreateImage(IMAQ_IMAGE_U8,0);
 imaqReadFile(SrcImg,"SrcImg.png",NULL,NULL);
 
 RefImg=imaqCreateImage(IMAQ_IMAGE_U8,0);
 imaqReadFile(RefImg,"RefImg.jpg",NULL,NULL);
 
 // Init FindPattern options
 o.angleRanges=NULL;
 o.minMatchScore=100;
 o.mode=IMAQ_MATCH_SHIFT_INVARIANT;
 o.numMatchesRequested=1;
 o.numRanges=0;
 o.showResult=TRUE;
 o.showSearchArea=TRUE;
 o.subpixelAccuracy=FALSE;

 for(i=0;i<25;i++)
 {
  printf("%d\n",i);
  
  pm=imaqFindPattern(SrcImg,RefImg,IMAQ_NO_ROTATED_RECT,&o,NULL,&n);
  
  Sleep(1000);

  if(pm) imaqDispose(pm);
 }
 
 return 0;
}

 

 

0 Kudos
Message 3 of 7
(5,202 Views)

Has there been any progress on this discussion?  I am also experiencing memory issues that my be related to the FindPattern function.  I believe I would find the results of this discussion very helpful.

 

Thanks,

Manson

Message Edited by A Wooten on 07-06-2009 09:17 AM
0 Kudos
Message 4 of 7
(4,914 Views)

It is still an issue for me!

I have attached two TaskManager images of my program. In the first image my program runs with two source code lines turned OFF:

 

    pm=imaqFindPattern(input_image,ref_image,RectROI,&PhotoFindPatternOptions,NULL,&n);
    if(pm!=NULL) {imaqDispose(pm); pm=NULL;}

 

And in the second image my program runs with these two source code lines turned ON.

 

I know this does not make much sense running the program with these lines turned ON, but it is a way to be sure that the memory leak is in these two lines.

 

The result is obious: there is a memory leak in this function!

 

MatchPattern turned OFF

 

MatchPattern turned ON

Message Edited by iai on 11-03-2009 02:55 AM
Message Edited by iai on 11-03-2009 02:56 AM
0 Kudos
Message 5 of 7
(4,688 Views)
Solution
Accepted by topic author RobKijger

Good news! After installing the NI-Vision update 8.6.1 the memory leak disappeared!

So, if you have memory issues with imaqFindPattern, locate, install and download the 27Mb NI update.

 

Message 6 of 7
(4,658 Views)
That is good news!  Unfortunately I am using an older version of the Vision Development module (v7.1.0).  Is there an update available  for my version?
0 Kudos
Message 7 of 7
(4,651 Views)