-
Notifications
You must be signed in to change notification settings - Fork 152
Fix memory leaks #180
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
Fix memory leaks #180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this change address this alledged memory leak?
The reference to queue[0]
becomes invalid right after queue = queue[1:]
. Since there are no more references to queue[0]
, the garbage collector will eventually collect and reclaim this piece of memory.
Signed-off-by: Aitor Perez Cedres <[email protected]>
Maybe this triggers GC faster? I haven't had time to reproduce the issue. |
I wrote an integration test to verify this behaviour. After profiling with your patch, I don't see a difference in allocations https://github.com/rabbitmq/amqp091-go/blob/test-for-pr-180/integration_test.go#L2008
This is with the patch in this PR.
|
Thanks for doing that @Zerpet |
During the test, the memory can not be recycled for 24 hours after consumption. |
I'll do it again at the weekend. |
This means that you ONLY see this issue using OS X? |
I'm not sure I follow. The The garbage collector will reclaim the memory of those objects. Lines 77 to 79 in 5656876
Since the reference |
I don't think that follows. Given Go's slice semantics, and barring any information available to the compiler that proves that (Depending on the program dynamics, an element may eventually be appended to the queue when the queue is at capacity, and in this case the live elements are copied into a new array and the old array is left to be GC'd eventually, along with the dead object. But that can take time.) |
@lars-t-hansen that's interesting. @Zerpet there is no harm in adding the statement. I will add a comment to explain it more. |
Thanks everyone. |
@lars-t-hansen I checked this with a simple program and you are right. Thank you for taking the time to explain this ❤️ @GXKe thank you for your contribution! |
not to take away from the fix introduced here and discussion, but we were experiencing uncontrolled memory growth that originated in the sdk (using the current latest version, 1.10.0), with memory profiling demonstrating traces similar to those seen in this discussion. Having had the fixed version and after researching, we came at the conclusion that the unbounded Line 59 in 5656876
The combination of |
Fixes #179