Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDoes `free()` actually get called? #20
Comments
|
As an aside; I couldn't find documentation clarifying the copy-assignment and copy-constructor of RcppGSL::vector perform a shallow copy (but I think this is true). Changing the behaviour of the destructor (to, say, call It made it difficult to design a(n exposed) class without this knowledge, and I had to look quite deep under the hood of Rcpp to be sure I understood what was going on. |
|
It's been years since I coded this but if it really leaked as you claim I am sure CRAN would have come after me via valgrind evidence. Rather than triggering it on-the-fly functions which with the dynamic runtime that R offers are somewhat murky, why don't you just add a print here in the destructor or here ? And possibly here and here ? |
|
I added valgrind found no memory leaks - however if I run |
|
I am out and about at the Chicago marathon so I can't add code tests but I am fairly certain I recollect this working as intended. With that, two caveats: you may need a |
|
Disreregards those links from earlier. Those are obviously not the destructors but just the |
|
I would need more time there than I have now -- I was just working in parallel on two other packages and PRs that had come in today. |
|
Speculation on my part; valgrind might not detect leaks if |
|
Not sure that it is. IIRC then GSL also just calls I have branch littered with |
I had a quick look inside gsl (which removes the need for my speculation) - it is correct that Odd that valgrind doesn't identify any leaks given the gradual consumption of memory (even when |
|
Valgrind is a fantastic tool. And it is rightly mentioned and highlighed in Writing R Extensions. But what helped me a few times was to establish what we could call "proper baselines". Think of simple C or C++ routines that allocates and then frees memory. With a |
|
The calls to |
|
It's now PR #22 which I likely merge soon after it passed all tests on reverse depends etc pp. |
correct 'allocated?' logic and actually call free() (closes #20)
I can't figure out if the
freemember function orgsl_vector_free()is ever called in the destructors of the Vector or vector types - it looks to me like no? The quickest-ugliest check on this I could manage is to use a static that takes the first gsl_vector.data passed to the function - and then prints the first element of the static data out each time the function is called.When free is explicitly called, the contents changes (unsure why the specific value is printed - must be a gsl thing). Now lets rely on the destructor instead;
Seems suspiciously like
free()wasn't called?