-2

I am a newbie in objective-c

I have a lot of memory issues, and a lot of alloc variables

-what to do?

rmaddy
  • 298,130
  • 40
  • 468
  • 517
Anurag Sharma
  • 2,823
  • 1
  • 21
  • 38

2 Answers2

2

First of all, in Objective-C in contrast to functions methods are nor called (but invoked via a dispatch) neither using () . The typical spelling for a method is -dealloc. Sending a message to execute it, is done with [] as in [self dealloc].

No, you cannot do this. Your code will break.

You never send a dealloc message directly. (Apple Doc)

If you have memory leaks with ARC, the reason are retain cycles. Read something about it. Most retain cycles are easy to detect. However, you can use the Instruments (Allocations) to detect them at runtime.

Amin Negm-Awad
  • 15,951
  • 3
  • 33
  • 50
  • thanks a lot, you helped me very well. But the thing is that : Let's say we have three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. What will happen in this case ? – Anurag Sharma Jul 11 '16 at 10:43
  • parent and child will leak, because they refer each other and are unreachable. This *is* a retain cycle. Break it. – Amin Negm-Awad Jul 11 '16 at 11:01
  • break it means what exactly? I searched for it but didn't get the right idea. Do you have any reference? – Anurag Sharma Jul 11 '16 at 11:40
  • In your case typically the reference from the child to the parent is built weakly, using the keyword `weak`. In such a case the parent would lose its last reference (the reference from child is weak), therefore will be deallocated, what takes away the last reference to the child, so it is deallocated, too. – Amin Negm-Awad Jul 11 '16 at 13:01
-1

When you will use ARC, you can not call dealloc ([super dealloc]). The compiler handles it for us. you can refer this link for more details :

You can use @autoreleasepool for better practice.

sunshine
  • 21
  • 5