@@ -15,6 +15,9 @@ class UnitTestMemoryLeaks : public WsjcppUnitTestBase {
1515 virtual bool doBeforeTest () override ;
1616 virtual void executeTest () override ;
1717 virtual bool doAfterTest () override ;
18+
19+ private:
20+ void createManyTimesObjects ();
1821};
1922
2023REGISTRY_WSJCPP_UNIT_TEST (UnitTestMemoryLeaks)
@@ -32,50 +35,38 @@ bool UnitTestMemoryLeaks::doBeforeTest() {
3235
3336// ---------------------------------------------------------------------
3437
35- void UnitTestMemoryLeaks::executeTest () {
36- double nBeforeVm, nBeforeRss;
37- double nAfterVm, nAfterRss;
38+ void UnitTestMemoryLeaks::createManyTimesObjects () {
3839 std::string sFilepath = " ./data-tests/for-memory-leak/some.yml" ;
3940 std::string sError ;
40-
41- // std::cout << "currentSize "<< getCurrentRSS() << std::endl;
42- // std::cout << "peakSize "<< getPeakRSS() << std::endl;
43-
44- // first use for memory alloc some
45- for (int i = 0 ; i < 1000 ; i++) {
41+ for (int i = 0 ; i < 10000 ; i++) {
4642 WsjcppYaml yaml;
4743 if (!compare (" Error parsing" , yaml.loadFromFile (sFilepath , sError ), true )) {
4844 WsjcppLog::err (TAG, sError );
4945 return ;
5046 }
5147 }
52-
48+ }
49+
50+ // ---------------------------------------------------------------------
51+
52+ void UnitTestMemoryLeaks::executeTest () {
53+ double nBeforeVm, nBeforeRss;
54+ double nAfterVm, nAfterRss;
55+ std::string sFilepath = " ./data-tests/for-memory-leak/some.yml" ;
56+
57+ // first use for memory alloc memory for work
58+ createManyTimesObjects ();
59+
5360 process_mem_usage (nBeforeVm, nBeforeRss);
54- // std::cout << "nBeforeVm: " << nBeforeVm << std::endl;
55- // std::cout << "nBeforeRss: " << nBeforeRss << std::endl;
5661 compare (" memory vm not null" , (int )nBeforeVm > 0 , true );
5762 compare (" memory vm not null" , (int )nBeforeRss > 0 , true );
5863
59- // std::cout << "currentSize "<< getCurrentRSS() << std::endl;
60- // std::cout << "peakSize "<< getPeakRSS() << std::endl;
61-
6264 // code again check the memoty leak
63-
64- for (int i = 0 ; i < 1000 ; i++) {
65- WsjcppYaml yaml;
66- if (!compare (" Error parsing" , yaml.loadFromFile (sFilepath , sError ), true )) {
67- WsjcppLog::err (TAG, sError );
68- return ;
69- }
70- }
65+ createManyTimesObjects ();
7166
7267 process_mem_usage (nAfterVm, nAfterRss);
73- // std::cout << "nAfterVm: " << nAfterVm << std::endl;
74- // std::cout << "nAfterRss: " << nAfterRss << std::endl;
7568 compare (" memory vm" , (int )nAfterVm, (int )nBeforeVm);
7669 compare (" memory rss" , (int )nAfterRss, (int )nBeforeRss);
77- // std::cout << "currentSize "<< getCurrentRSS() << std::endl;
78- // std::cout << "peakSize "<< getPeakRSS() << std::endl;
7970}
8071
8172// ---------------------------------------------------------------------
0 commit comments