Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different result first time I run profmem... #20

Closed
minesrebollo opened this issue Oct 19, 2020 · 1 comment
Closed

Different result first time I run profmem... #20

minesrebollo opened this issue Oct 19, 2020 · 1 comment
Labels

Comments

@minesrebollo
Copy link

minesrebollo commented Oct 19, 2020

Hi! I am trying to use profmem to compute memory usage of a set of functions and I get very different results when I run the same command again (it goes from 273376 to 36648 bytes).

Here is a reproducible example:

rm(list = ls())
r <- profmem({ 
  for (i in 1:5){
    for (j in 1:50){
      cat(i,j)
    }}
})
total(r) #19200
s <- profmem({ 
  for (i in 1:5){
    for (j in 1:50){
      cat(i,j)
    }}
})
total(s) #19760
t <- profmem({ 
  for (i in 1:5){
    for (j in 1:50){
      cat(i,j)
    }}
})
total(t) #19760

In this example memory usage increases while in my case it decreases a lot. Which one would be the "real" memory use, the first one or the following ones? Thank you!!!

Best,
Inés

@HenrikBengtsson
Copy link
Owner

Better late than never. Two comments:

Yes, when you start a fresh R session, there are things that will be additional things that will allocated the first time you evaluate some code. Thus, you often have to call it more than ones to get a good better idea about what's going on in your code. I don't fully understand exactly what is going on under the hood in R here, but if one would understand it better, maybe one could create a profmem::burnin() function that one can call once to fix this. Maybe it could even be done automagically by the profmem package, so the user does not have to do anything.

In this example memory usage increases while in my case it decreases a lot. Which one would be the "real" memory use, the first one or the following ones?

So, please note that utils::Rprofmem(), and therefore also profmem::profmem(), does not log memory deallocations, cf. https://github.com/HenrikBengtsson/profmem#what-is-logged. Because of this, you cannot use these data to figure out the amount of memory currently allocated, i.e. total() only reports on the total amount of allocations. FWIW, I've added it to the wishlist to have utils::Rprofmem() record also deallocations, c. HenrikBengtsson/Wishlist-for-R#25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants