Skip to content

Commit

Permalink
IGNITE-11654: [ML] Memory leak in KNNClassificationModel (#6392)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaleslaw committed Apr 3, 2019
1 parent 4daa681 commit db38352
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Expand Up @@ -68,7 +68,7 @@ public DistanceMeasure distanceMeasure() {
*
* @param vec Vector.
*/
public Integer predict(Vector vec) {
@Override public Integer predict(Vector vec) {
int res = -1;
double minDist = Double.POSITIVE_INFINITY;

Expand Down
Expand Up @@ -33,5 +33,5 @@ public interface Model<I, O> extends AutoCloseable {
public O predict(I input);

/** {@inheritDoc} */
public void close();
}
@Override public void close();
}
Expand Up @@ -229,5 +229,5 @@ protected void copyParametersFrom(NNClassificationModel mdl) {
}

/** */
public abstract <P> void saveModel(Exporter<KNNModelFormat, P> exporter, P path);
@Override public abstract <P> void saveModel(Exporter<KNNModelFormat, P> exporter, P path);
}
Expand Up @@ -38,6 +38,9 @@

/**
* kNN algorithm model to solve multi-class classification task.
*
* NOTE: This model is especial, because it takes dataset as an input.
* The dataset (or datasets in case of model updating) are closing automatically.
*/
public class KNNClassificationModel extends NNClassificationModel implements Exportable<KNNModelFormat> {
/** */
Expand Down Expand Up @@ -144,4 +147,16 @@ public void copyStateFrom(KNNClassificationModel mdl) {
this.copyParametersFrom(mdl);
datasets.addAll(mdl.datasets);
}

/** {@inheritDoc} */
@Override public void close() {
for (int i = 0; i < datasets.size(); i++) {
try {
datasets.get(i).close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}

0 comments on commit db38352

Please sign in to comment.