-
Notifications
You must be signed in to change notification settings - Fork 99
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
Memory leaks when memoizing class methods #47
Comments
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). |
Closes matthewrudy#47 Updates the readme to mention memoized class methods can lead to memory bloat.
Closes matthewrudy#47 Updates the readme to mention memoized class methods can lead to memory bloat.
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
memoize :with_overdue_taxes
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
The text was updated successfully, but these errors were encountered: