Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Intermediate Swift 2 Memory Management in Swift Weak References

Harish Yerra
Harish Yerra
10,031 Points

How do we know when we run into a memory leak?

Are there tools which tell us that we are running into a memory leak? Because I know when I am creating an application memory management won't be at the very forefront of my thought process, and it's easy to miss catching a memory leak. How do we debug and find memory leaks?

2 Answers

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

To put it short: Instruments. Don't run your app as usual via Xcode, but change it to Profile. Xcode will present you a set of tools to profile your app. There is "Leaks" and "Allocations". You can search for specific class names to hide the system processes. Whenever objects are around even if you dismissed the corresponding view controller, for example, this could be a memory leak. If the view controller is not deallocated after it's been removed from the view, and the number of one and the same controller increases with every time you open it, it's very likely a memory leak.

I know this explanation is very vague, I will try to refine it over time and add some links, I just wanted to give you a headstart first. Moreover, it gives you some hints on what to google ;)

P.S. Memory management has to be at the very forefront while you are coding. Make yourself familiar with ARC and autoreleasepools, the sooner the better :)

Harish Yerra
Harish Yerra
10,031 Points

Ok :)

Thanks for your help! I will try to get my hands on this stuff more! Hopefully they release a course on Treehouse soon covering Memory Management in depth.

Kevin Gutowski
Kevin Gutowski
4,082 Points

I imagine that a lot of this will change with the new updates to visualize memory leak paths in Xcode 8?