I found a memory leak in NIVision.particleFilter(). I believe WPI is working on it...
If you feel daring, you could modify WPILibJ's NIVision class (sunspotfrcsdk/lib/WPILibJ/src/edu/wpi/first/wpilibj/image/NIVision.java) with this UNTESTED FIX:
Code:
/* THIS IS AN UNTESTED FIX */
public static int particleFilter(Pointer dest, Pointer source, CriteriaCollection collection) throws NIVisionException {
Pointer particleFilterOptions = new Pointer(16);
particleFilterOptions.setInt(0, 0);
particleFilterOptions.setInt(4, 0);
particleFilterOptions.setInt(8, 0);
particleFilterOptions.setInt(12, 1);
IntByReference i = new IntByReference(0);
Pointer criteriaArray = collection.getCriteriaArray();
assertCleanStatus(imaqParticleFilter4Fn.call7(dest.address().toUWord().toPrimitive(), // dest image
source.address().toUWord().toPrimitive(), // source image
criteriaArray.address().toUWord().toPrimitive(), // array of criteria
collection.getNumberOfCriteria(), // number of criteria in the array
particleFilterOptions.address().toUWord().toPrimitive(), // particle filter options
0, // Region of interest
i.getPointer().address().toUWord().toPrimitive())); // returned number of particles
int numberOfParticles = i.getValue();
i.free();
criteriaArray.free();
particleFilterOptions.free();
return numberOfParticles;
}