When using the instruments leak profiler, I ran into a bunch of leaks involving juce’s URLConnectionState. The simple fix had to do with the way that the NSURLSession was being released. According to apple’s documentation:
The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you do not invalidate the session by calling the
invalidateAndCancel
or
finishTasksAndInvalidate
method, your app leaks memory until it exits.
To fix the leak All I did was add
[session finishTasksAndInvalidate];
to the destructor of URLConnectionState before we release it.