djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 374 forks source link

Memory leak in enhanced mode #137

Closed korhner closed 8 years ago

korhner commented 9 years ago

APNs objects are not garbage collected in ehnaced mode. You can reproduce this by creating and disconnecting a new APNs object in a loop multiple times, sending notifications and disconnecting and see memory growing. Easy to check using a package like pympler.

APNs has a reference to GatewayConnection(APNsConnection). GatewayConnection(APNsConnection) and ErrorResponseHandlerWorker(threading.Thread) have a circular reference to each other. In addition, python does not garbage collect circular references where a class has __del__ defines (APNsConnection in this case) which causes those object to remain in memory.

Removing __del__ from APNsConnection seems to fix memory issue but I am not sure if it introduces other side effects like not cleaning connections properly.

Hope I was clear.

djacobs commented 8 years ago

Should be resolved with the above.