Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix memory leak of optimizer and executer
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadiaphy committed Feb 22, 2019
1 parent 43fde1a commit fb43b71
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpp-package/example/alexnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ int main(int argc, char const *argv[]) {
}
/*don't foget to release the executor*/
delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
10 changes: 10 additions & 0 deletions cpp-package/example/charRNN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ void train(const std::string file, int batch_size, int max_epoch, int start_epoc
std::string filepath = prefix + "-" + std::to_string(epoch) + ".params";
SaveCheckpoint(filepath, RNN, exe);
}

delete exe;
delete opt;
}

/*The original example, rnn_cell_demo.py, uses default Xavier as initalizer, which relies on
Expand Down Expand Up @@ -577,6 +580,9 @@ void trainWithBuiltInRNNOp(const std::string file, int batch_size, int max_epoch
std::string filepath = prefix + "-" + std::to_string(epoch) + ".params";
SaveCheckpoint(filepath, RNN, exe);
}

delete exe;
delete opt;
}

void predict(std::wstring* ptext, int sequence_length, const std::string param_file,
Expand Down Expand Up @@ -639,6 +645,8 @@ void predict(std::wstring* ptext, int sequence_length, const std::string param_f
next = charIndices[n];
ptext->push_back(next);
}

delete exe;
}

void predictWithBuiltInRNNOp(std::wstring* ptext, int sequence_length, const std::string param_file,
Expand Down Expand Up @@ -693,6 +701,8 @@ void predictWithBuiltInRNNOp(std::wstring* ptext, int sequence_length, const std
next = charIndices[n];
ptext->push_back(next);
}

delete exe;
}

int main(int argc, char** argv) {
Expand Down
1 change: 1 addition & 0 deletions cpp-package/example/googlenet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ int main(int argc, char const *argv[]) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/inception_bn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ int main(int argc, char const *argv[]) {
LG << "Validation Accuracy: " << val_acc.Get();
}
delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/lenet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Lenet {
<< ", accuracy: " << ValAccuracy(batch_size * 10, lenet);
}
delete exe;
delete opt;
}

private:
Expand Down
1 change: 1 addition & 0 deletions cpp-package/example/lenet_with_mxdataiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ int main(int argc, char const *argv[]) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/mlp_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ int main(int argc, char** argv) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/mlp_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ int main(int argc, char** argv) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/mlp_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ int main(int argc, char** argv) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/resnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ int main(int argc, char const *argv[]) {
LG << "Validation Accuracy: " << val_acc.Get();
}
delete exec;
delete opt;
MXNotifyShutdown();
return 0;
}
1 change: 1 addition & 0 deletions cpp-package/example/test_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int main(int argc, char** argv) {
opt = OptimizerRegistry::Find("adam");
int ret = (opt == 0) ? 1 : 0;

delete opt;
MXNotifyShutdown();
return ret;
}
1 change: 1 addition & 0 deletions cpp-package/example/test_score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ int main(int argc, char** argv) {
}

delete exec;
delete opt;
MXNotifyShutdown();
return score >= MIN_SCORE ? 0 : 1;
}

0 comments on commit fb43b71

Please sign in to comment.