jfcote....@gmail.com
unread,Mar 13, 2013, 9:22:25 AM3/13/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to accor...@googlegroups.com
Hi César,
I think there may be a memory leak somewhere in the Compute function of the object KMeans. I didn't look at the code itself since I'm just using the DLL.
In my application, I run a KMeans on a lot of picture in a loop to cluster them (like 800 pictures). When I put the kMeans.Compute fonction in comments, I don't have memory leak. When I remove the comment, the memory consumption start around 80 000 K and can grow up to 500 000 K, depending on the number of picture in the set. When the loop is finished, the memory don't go down, it stay there.
I've searched for a Dispose in the kmeans object but there is none. Here is the code (very simple). Put that in a loop and you should got the bug.
// Retrieve the number of clusters
int k = 3;
// Load original image
Bitmap image = _image.ToBitmap();
// Create conversors
ImageToArray imageToArray = new ImageToArray(min: 0, max: +255);
ArrayToImage arrayToImage = new ArrayToImage(image.Width, image.Height, min: 0, max: +255);
// Transform the image into an array of pixel values
double[][] pixels;
imageToArray.Convert(image, out pixels);
// Create a K-Means algorithm using given k and a
// square euclidean distance as distance metric.
KMeans kmeans = new KMeans(k, Accord.Math.Distance.SquareEuclidean);
// Compute the K-Means algorithm until the difference in
// cluster centroids between two iterations is below 0.05
kmeans.Randomize(pixels, true);
int[] idx = kmeans.Compute(pixels, 0.1);
// Replace every pixel with its corresponding centroid
pixels.ApplyInPlace((x, i) => kmeans.Clusters.Centroids[idx[i]]);
Since my application will need to work on video frame of very long video, it can't work if there is memory leak. Let me know what you think about it and if it's a real bug, I can make an entry in the bug system.