Open hgani opened 8 years ago
I believe you have understood it correctly. I agree that it is worth mentioning in the README.
I don't believe this is a memory leak. The intention of the code is to cache the results as long as the class object exists. The code succeeds.
A memory leak is when the author's intent is to free up memory, but the code isn't written to do so.
@dogweather I agree that it is not a leak from the gem's point of view, because as you said, it succeeds doing what it promises.
But this discussion is intended to remind developers to be careful when using the gem in certain situations as it can unexpectedly prevent objects from being freed forever (until the process is restarted).
Hi,
I'd like to confirm my understanding about how class method memoization works in order to establish a best practice for myself and hopefully will be useful for others as well.
Here's an example ...
class Person
class << self extend Memoist def with_overdue_taxes(arg)
...
end
end
If arg is an integer that varies between 1 to 1 million, that means I am potentially keeping 1 million cached entries in memory. And this won't be garbage collected because it's referenced by the class, so the server will run out of memory quickly.
Is this right?
If so, then perhaps it's worth mentioning this in the README to help fellow programmers avoid this.
Thanks