0

I have a ViewController like below;

All of the delegates are weak, what else can it be a strong reference then ? I can't get it, and the ViewController won't dealloc that is really bad.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
anna
  • 662
  • 5
  • 28
  • does the vc that does the pushing of this vc keep a reference to it? – Fonix Dec 17 '14 at 03:28
  • 3
    does your `GoodDetailViewController` get referenced within a block at all (or self if within the `GoodDetailViewController`)? and more specifically is that block kept around somewhere, because unless you specifically tell a block to use a weak reference, everything captured in a block is strong – Fonix Dec 17 '14 at 04:12
  • 1
    Check if you have some NSTimer in the pushed VC, or something else which is being used in the pushed VC, as in my case invalidating NSTimer caused dealloc to be called. – zaheer Dec 17 '14 at 04:17
  • @Fonix I do have some blocks in GoodDetailViewController, and as you mentioned, I'm trying to check the blocks. I found this http://stackoverflow.com/questions/11822476/weak-references-in-blocks-and-retain-cycles/11822842#11822842. I will read it. I will let you know if I have results. – anna Dec 17 '14 at 05:34
  • @zaheer , I don't have anything like NSTimer. I will check my blocks. – anna Dec 17 '14 at 05:35
  • Yup, check those, and cancel their processing before pop-ing/unwinding the VC. – zaheer Dec 17 '14 at 05:48
  • @zaheer , I have another vc where I used blocks, and vc can dealloc. I compared the two vcs, they use blocks assembly. I doubt the block is not a problem. – anna Dec 17 '14 at 06:10
  • What is TableViewCellGoodPrice and why is there a strong reference to one? – Mike Taverne Dec 17 '14 at 06:11
  • @MikeTaverne , It plays a role of tableview header, I should give it a strong reference if it's a subview. The other TableViewCellGoodxxxxs are cell prototypes for tableview. – anna Dec 17 '14 at 06:16
  • @Fonix , I found the strong reference by another subview, wow, finally. Thanks all the same for your suggestions that brought me light.But I have a lot of blocks without weak self, and they all get dealloc. So I can't understand in what condition the error you described will happen. Can you tell me? – anna Dec 17 '14 at 09:43
  • @anna, basically if you use self in a block, then keep a reference to that block in self(in this case your `GoodDetailViewController`), the block will have a strong reference to self, and self will have a strong reference to the block, hence a retain cycle. this isnt the only way, but the simplest case i guess. – Fonix Dec 18 '14 at 02:01

2 Answers2

0

It's tough to know what is causing the leak without seeing all of the code which may be referring to your controller. However, Apple provides a good tool for hunting this type of problem down with Instruments. Here is a tutorial for using Instruments that may be helpful:

http://www.raywenderlich.com/2696/instruments-tutorial-for-ios-how-to-debug-memory-leaks

Here is Apple's documentation on the topic:

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/MemoryManagementforYourApp/MemoryManagementforYourApp.html#//apple_ref/doc/uid/TP40004652-CH11-SW1

Snack Cake
  • 186
  • 6
  • It's really hard, I have tried for 2 days and have no clue at all. I tried to use Instruments and check the memory usuage, I do find some problem but not this one. I need to dig more. – anna Dec 17 '14 at 03:44
0

You just have to believe that there must be some strong references if vc can't get dealloc. Check it again and again.

anna
  • 662
  • 5
  • 28