vrunge / gfpop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memory leak

tdhock opened this issue · comments

Hi @vrunge my PhD student @AtiyehFtn is running gfpop (see precise version in install_github line below) and running out of error because of a memory leak. I investigated on my linux machine using valgrind and I observe a memory leak:

tdhock@recycled:~/R/gfpop-bug$ R --vanilla -d valgrind < gfpop.R
==7799== Memcheck, a memory error detector
==7799== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==7799== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==7799== Command: /home/tdhock/lib/R/bin/exec/R --vanilla
==7799== 

R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: i686-pc-linux-gnu (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> set.seed(1)
> x <- rnorm(100)
> g <- gfpop::graph(type="std")
> w <- rep(1, length(x))
> fit <- gfpop::gfpop(x, w, g)
> print(fit)
$changepoints
 [1]   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
[20]  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39
[39]  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58
[58]  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77
[77]  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96
[96]  97  98  99 100

$states
integer(0)

$forced
integer(0)

$means
 [1]  0.183643324 -0.835628612  1.595280802  0.329507772 -0.820468384
 [6]  0.487429052  0.738324705  0.575781352 -0.305388387  1.511781168
[11]  0.389843236 -0.621240581 -2.214699887  1.124930918 -0.044933609
[16] -0.016190263  0.943836211  0.821221195  0.593901321  0.918977372
[21]  0.782136301  0.074564983 -1.989351696  0.619825748 -0.056128740
[26] -0.155795507 -1.470752384 -0.478150055  0.417941560  1.358679552
[31] -0.102787727  0.387671612 -0.053805041 -1.377059557 -0.414994563
[36] -0.394289954 -0.059313397  1.100025372  0.763175748 -0.164523596
[41] -0.253361680  0.696963375  0.556663199 -0.688755695 -0.707495157
[46]  0.364581962  0.768532925 -0.112346212  0.881107726  0.398105880
[51] -0.612026393  0.341119691 -1.129363096  1.433023702  1.980399899
[56] -0.367221476 -1.044134626  0.569719627 -0.135054604  2.401617761
[61] -0.039240003  0.689739362  0.028002159 -0.743273209  0.188792300
[66] -1.804958629  1.465554862  0.153253338  2.172611670  0.475509529
[71] -0.709946431  0.610726353 -0.934097632 -1.253633400  0.291446236
[76] -0.443291873  0.001105352  0.074341324 -0.589520946 -0.568668733
[81] -0.135178615  1.178086997 -1.523566800  0.593946188  0.332950371
[86]  1.063099837 -0.304183924  0.370018810  0.267098791 -0.542520031
[91]  1.207867806  1.160402616  0.700213650  1.586833455  0.558486426
[96] -1.276592208 -0.573265414 -1.224612615 -0.473400636

$cost
[1] 0

attr(,"class")
[1] "gfpop"
> devtools::session_info()
Session info ------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 system   i686, linux-gnu             
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Phoenix             
 date     2019-10-24                  

Packages ----------------------------------------------------------------------
 package   * version date       source        
 base      * 3.6.0   2019-05-15 local         
 compiler    3.6.0   2019-05-15 local         
 datasets  * 3.6.0   2019-05-15 local         
 devtools    1.13.5  2018-02-18 CRAN (R 3.5.0)
 digest      0.6.15  2018-01-28 CRAN (R 3.5.0)
 gfpop       0.1.3   2019-10-24 local         
 graphics  * 3.6.0   2019-05-15 local         
 grDevices * 3.6.0   2019-05-15 local         
 memoise     1.1.0   2017-04-21 CRAN (R 3.5.0)
 methods   * 3.6.0   2019-05-15 local         
 Rcpp        1.0.1   2019-03-17 CRAN (R 3.6.0)
 stats     * 3.6.0   2019-05-15 local         
 utils     * 3.6.0   2019-05-15 local         
 withr       2.1.2   2018-03-15 CRAN (R 3.5.0)
> 
==7799== 
==7799== HEAP SUMMARY:
==7799==     in use at exit: 34,689,521 bytes in 15,335 blocks
==7799==   total heap usage: 38,721 allocs, 23,386 frees, 79,644,002 bytes allocated
==7799== 
==7799== 56 bytes in 1 blocks are definitely lost in loss record 46 of 2,078
==7799==    at 0x4830FF5: operator new(unsigned int) (/home/tdhock/R/valgrind-3.14.0/coregrind/m_replacemalloc/vg_replace_malloc.c:328)
==7799==    by 0xBA731DA: Omega::Omega(Graph, Bound, Robust) (/home/tdhock/R/gfpop/src/Omega.cpp:28)
==7799==    by 0xBA85171: gfpopTransfer(Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double, double, double) (/home/tdhock/R/gfpop/src/main.cpp:90)
==7799==    by 0xBA7B99E: _gfpop_gfpopTransfer (/home/tdhock/R/gfpop/src/RcppExports.cpp:22)
==7799==    by 0x4902968: R_doDotCall (/home/tdhock/R/R-3.6.0/src/main/dotcode.c:586)
==7799==    by 0x493DDC3: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:7283)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799==    by 0x49495D7: R_execClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1780)
==7799==    by 0x494A500: Rf_applyClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1706)
==7799==    by 0x493E844: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:6733)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799==    by 0x49495D7: R_execClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1780)
==7799== 
==7799== 56 bytes in 1 blocks are definitely lost in loss record 47 of 2,078
==7799==    at 0x4830FF5: operator new(unsigned int) (/home/tdhock/R/valgrind-3.14.0/coregrind/m_replacemalloc/vg_replace_malloc.c:328)
==7799==    by 0xBA7798C: Piece::operator_std_min_argmin(int, int&, double&, Bound const&) (/home/tdhock/R/gfpop/src/Piece.cpp:647)
==7799==    by 0xBA7169E: Omega::fpop1d_graph_std(Data const&) (/home/tdhock/R/gfpop/src/Omega.cpp:278)
==7799==    by 0xBA8525A: gfpopTransfer(Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double, double, double) (/home/tdhock/R/gfpop/src/main.cpp:93)
==7799==    by 0xBA7B99E: _gfpop_gfpopTransfer (/home/tdhock/R/gfpop/src/RcppExports.cpp:22)
==7799==    by 0x4902968: R_doDotCall (/home/tdhock/R/R-3.6.0/src/main/dotcode.c:586)
==7799==    by 0x493DDC3: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:7283)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799==    by 0x49495D7: R_execClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1780)
==7799==    by 0x494A500: Rf_applyClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1706)
==7799==    by 0x493E844: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:6733)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799== 
==7799== 56 bytes in 1 blocks are definitely lost in loss record 48 of 2,078
==7799==    at 0x4830FF5: operator new(unsigned int) (/home/tdhock/R/valgrind-3.14.0/coregrind/m_replacemalloc/vg_replace_malloc.c:328)
==7799==    by 0xBA796E5: Piece::min_function(Piece*, double) (/home/tdhock/R/gfpop/src/Piece.cpp:1001)
==7799==    by 0xBA715EC: Omega::fpop1d_graph_std(Data const&) (/home/tdhock/R/gfpop/src/Omega.cpp:284)
==7799==    by 0xBA8525A: gfpopTransfer(Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::Vector<14, Rcpp::PreserveStorage>, Rcpp::DataFrame_Impl<Rcpp::PreserveStorage>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double, double, double) (/home/tdhock/R/gfpop/src/main.cpp:93)
==7799==    by 0xBA7B99E: _gfpop_gfpopTransfer (/home/tdhock/R/gfpop/src/RcppExports.cpp:22)
==7799==    by 0x4902968: R_doDotCall (/home/tdhock/R/R-3.6.0/src/main/dotcode.c:586)
==7799==    by 0x493DDC3: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:7283)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799==    by 0x49495D7: R_execClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1780)
==7799==    by 0x494A500: Rf_applyClosure (/home/tdhock/R/R-3.6.0/src/main/eval.c:1706)
==7799==    by 0x493E844: bcEval (/home/tdhock/R/R-3.6.0/src/main/eval.c:6733)
==7799==    by 0x494775D: Rf_eval (/home/tdhock/R/R-3.6.0/src/main/eval.c:620)
==7799== 
==7799== LEAK SUMMARY:
==7799==    definitely lost: 168 bytes in 3 blocks
==7799==    indirectly lost: 0 bytes in 0 blocks
==7799==      possibly lost: 0 bytes in 0 blocks
==7799==    still reachable: 34,689,353 bytes in 15,332 blocks
==7799==                       of which reachable via heuristic:
==7799==                         newarray           : 3,880 bytes in 1 blocks
==7799==         suppressed: 0 bytes in 0 blocks
==7799== Reachable blocks (those to which a pointer was found) are not shown.
==7799== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7799== 
==7799== For counts of detected and suppressed errors, rerun with: -v
==7799== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
tdhock@recycled:~/R/gfpop-bug$ 

it says there is a "new" on this line ==7799== by 0xBA731DA: Omega::Omega(Graph, Bound, Robust) (/home/tdhock/R/gfpop/src/Omega.cpp:28) that has no corresponding "delete" -- can you please investigate/fix?

i confirm this has been fixed