Daniel C Garcia

Hi all,

I have an application that generates a list of all fingerprint images in a selected folder, then goes down the list comparing each fingerprint and returns a score for each match.

The first thing it does is generate an Array List of all the files. It opens the first file and copies the data into a byte array, opens the second file and does the same. Then it calls getScore(byte array 1, byte array 2). getScore() calls various functions of our fingerprint matching API and returns an integer score. the score and file names of the files compared gets written to a text file. It does that for every file from index 1 to N where N is the total number of files. It then removes element 0 in the array. The new element 0 gets read and so forth until it gets a score for every comparison, repeat.

I do a Dispose() on every stream after it's used and I set the byte arrays to null after the score is returned. Should I be doing anything else as I keep getting out of memory exceptions I tried adding GC.Collect() but that just causes it to crash after a while.

Thanks.


Re: Visual C# General Out of memory exception

Peter Ritchie

Maybe you can post some code the shows how to reproduce the problem It could be many things...




Re: Visual C# General Out of memory exception

OmegaMan

I always laugh at CSI / crime shows when they match prints by flashing each print on the screen til it gets a hit....<g> If you are doing that...don't and save memory.

How big are the byte arrays If they are over 85K in size it gets placed in the Large Object Heap due to its size. If you are creating many of those arrays, it will fragment the LOH which is not cleared up as quickly as the other generation memory areas.





Re: Visual C# General Out of memory exception

Daniel C Garcia

Don't follow CSI. Basically the image are Portable Gray Map files of various sizes. When I first open the files I read the first three headers to obtain the size of the image in rows by columns. I then do a image = new byte[row*col]. The largest image I'm dealing with at the moment is 512x512.




Re: Visual C# General Out of memory exception

OmegaMan

How many images does a standard run compare against





Re: Visual C# General Out of memory exception

Daniel C Garcia

Well it depends on how many images are in a selected folder. Right now I have 1094 images. So the current process goes open image 1 stores byte array, then does a for loop from index 2-1094. The first element is then removed. Image 2 is now considered image 1 so it then compares image 1 to images 2 - 1093 and so forth. Right now it can handle about 60 iterations of that.




Re: Visual C# General Out of memory exception

OmegaMan

If you have an array of

byte[,] ar256 = new byte[256,256];

that will be placed into the Generation 0 (non Large Object Heap) but an array of 512

byte[,] ar512 = new byte[512,512];

is placed in the LOH. Can you reuse this byte buffer instead of creating a new one for each image





Re: Visual C# General Out of memory exception

Daniel C Garcia

That was a thought, but then I really don't have a way of knowing ahead of time how large a file I'll have to deal with, I'll need to talk it over with my coworkers.




Re: Visual C# General Out of memory exception

Daniel C Garcia

Unless you meant reusing the same byte array for both images being compared, can't do that as our dll is expecting both arrays. I'm currently running a test, the file is up to 4.4MB. I'll see how using two fixed arrays would affect it afterwards.




Re: Visual C# General Out of memory exception

OmegaMan

Daniel C Garcia wrote:
Unless you meant reusing the same byte array for both images being compared, can't do that as our dll is expecting both arrays. I'm currently running a test, the file is up to 4.4MB. I'll see how using two fixed arrays would affect it afterwards.


No, have at least two. With the intent to resuse the second array for the 2-N images by creating a super sized one and then zeroing out the array values between images changes.