kasketis / netfox

A lightweight, one line setup, iOS / OSX network debugging library! 🦊
MIT License
3.67k stars 374 forks source link

Fix memory leaks by invalidating session after cancelling tasks #209

Closed pauluhn closed 2 years ago

pauluhn commented 3 years ago

Mojio team noticed memory leaks within the networking layer with netfox integrated for debugging purposes. After this fix, we no longer see the memory leaks.

You can test this by looking at the memory graph before/after this fix.

Also, from the URLSession documentation:

Important The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you don’t invalidate the session, your app leaks memory until the app terminates.

ljoraanstad commented 3 years ago

+1, I also found this issue to be present when performing an action that begins a series of many network requests. Eventually the requests would get bogged down and start to run into weird issues with timeouts, etc. until you eventually aren't able to launch the app.