Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
GCM Notification Memory Leak #90
I'm maintaining a large scale notification push service (~5-20 million per day). Lately the server has been getting more and more bloated eating up all available memory and keeping many threads open (over 5GB of memory and having ~3000 threads open).
I've profiled the problem and it seems the crux of the problem is that GCM messages are kept alive and cannot be collected by the GC. According to a memory profiler I used, they are kept alive by the AsyncParam objects used in HttpRequests callbacks.
I've looked through the code and I believe I found the problem in the error handling of GCM notifications:
From row 221 at PushSharp.Android.TransportAsync:
The problem here is that the functions throws out errors, thereby bypassing the asyncParam.WebResponse.Close() line and causing the WebResponses to not close, keeping the requests/threads open which are still referencing the GCM Messages and thus they cannot be collected, causing threads/memory to pile up.
I have altered the code to
The service has been behaving since.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
It is better to call in finally block instead of the catch block.