Swift: Tracking memory leaks in tests

Daren Hayward
Feb 15, 2022

--

Bugs are a common in production code, especially those which are not driven by tests.

Memory leaks fall into the same category, until today I did not understand that there is a simple way to ensure that all references to an object are released.

Powerful, yet simple!

Now any object that is created in a test can be tracked by calling the trackForMemoryLeaks() and passing the object to be tracked. If there is a leak in the production code, the test will fail and it can be fixed removing the potential memory leak, great!

This is just one of the new things I’ve already learned in my training at Essential Developer

--

--

Daren Hayward

A family man with three girls with a heavy interest in software development. From embedded software to mobile applications, waterfall to agile.