URLConnectionState leak and a fix

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.

1 Like

Yep, good catch. I’ll add that

Hi, this fix isn’t working my end. Just to double check, ~URLConnectionState() now looks like this:

    [headers release];
    [session finishTasksAndInvalidate];
    [session release];

Thank you.

It’s on the develop branch here - cb1f026

Thank you,