10

As I start working in swift, I am curious in memory mgmt. As we all know that during any object creation or assignment of data into that object it takes memory. How can we check that a particular object has released the memory. I used xcode memory report to see memory status and fluctuations.

Here is a sample of images:

enter image description here

enter image description here

How can release memory if I already set nil into the objects.

Gourav Joshi
  • 2,419
  • 2
  • 27
  • 45
  • Thanks for comment, However I also check allocations and leaks via instruments. Ok I will do as you mentioned.... – Gourav Joshi Oct 07 '16 at 06:16
  • *"How can we check that a particular object has released the memory"* and *"How can release memory if I already set nil into the objects"* are two different questions. – Martin R Oct 07 '16 at 06:38
  • Yes, For both has only one aim to get release memory. The last line for justification. – Gourav Joshi Oct 07 '16 at 06:42

3 Answers3

5

Use instruments to track the lifecycle of an object than just Xcode because it gives you the allocation details at much higher level.

Check out the answer at https://stackoverflow.com/a/14891837/5133769. Though it was explained with old instruments it still works.

Community
  • 1
  • 1
Vikram Parimi
  • 777
  • 6
  • 29
3

Some objects are very small and it could be difficult to see in Memory profiling which one is released. This tool is helpful for finding memory leaks in an app. To check was some object released from memory or wasn't you can setup breakpoints or logs in dealloc() method for objective c and in deinit() method for swift.

shpasta
  • 1,913
  • 15
  • 21
2

Using instruments checking for leaks or allocations is the recommended way.

You can also set breakpoints or add logs to the dealloc method.