Monday, July 16, 2012

How to check memory leaks in XCode 4 ?

You need to go to Product>Profile on the top menu of XCode 4 as shown in screenshot below.




























Then you will see following window, you can just choose Leaks and Press Profile button, it will start the Instrument and start tracking leaks and allocation.






































As soon as you press Profile, it will start Instrument and the simulator/device(You can change in the settings of the Instrument whether you want to run it on simulator or device) will start running the app.
You scroll through various pages on your app. While doing so,  if you view the red line in Leaks windows of Instrument as shown below then you have memory leak detected ! You can move the dotted line with slider to find out how many bytes leaked at what time in a small yellow pop up.































When you double click the red thick line of memory leak as shown  above , in the lower portion of the Instrument you will be able to see all the leaks and related info. If I want to find detailed info about a particular leak,  in this tutorial as you can see the blue highlighted line of leak, I am going to inspect about that leak hence I will just click the arrow which comes up in its address field.










This will refresh the window and tell you the details with  Responsible Caller column in the end of the table , it gives the specific method  name where the leaks has occurred. If you double click the row, it will open that corresponding .m file where that method has been implemented. 


































Now you can see that the line is highlighted where the leak has occurred in the method of a .m file in the project.










 Hope this helps to someone new in fixing memory leaks !

No comments:

Post a Comment